-
Notifications
You must be signed in to change notification settings - Fork 362
FFI: implement Room::list_threads
#5953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: viktorstrate <viktorstrate@gmail.com>
| let roots = self.inner.list_threads(inner_opts).await?; | ||
|
|
||
| Ok(ThreadRoots { | ||
| chunk: roots.chunk.into_iter().map(|x| x.into()).collect(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line fails to compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome! Thanks for working on this. I managed to get it to compile with this change:
$ git diff
diff --git a/bindings/matrix-sdk-ffi/src/room/mod.rs b/bindings/matrix-sdk-ffi/src/room/mod.rs
index 29ca13b5ef..e4daa65e80 100644
--- a/bindings/matrix-sdk-ffi/src/room/mod.rs
+++ b/bindings/matrix-sdk-ffi/src/room/mod.rs
@@ -1243,7 +1243,17 @@ impl Room {
let roots = self.inner.list_threads(inner_opts).await?;
Ok(ThreadRoots {
- chunk: roots.chunk.into_iter().map(|x| x.into()).collect(),
+ chunk: roots
+ .chunk
+ .into_iter()
+ .filter_map(|timeline_event| {
+ timeline_event
+ .raw()
+ .deserialize()
+ .ok()
+ .map(|any_timeline_event| TimelineEvent(Box::new(any_timeline_event)))
+ })
+ .collect(),
prev_batch_token: roots.prev_batch_token,
})
}
This solves the problem of how to convert from a matrix_sdk_common::deserialized_responses::TimelineEvent into a matrix_sdk_ffi::event::TimelineEvent (oh how I hate things with the same name!) by using the cheat/trick of converting it to JSON (.raw()) and then parsing it (.deserialize). It then ignores any errors in that process by converting errors to None (.ok()) and removing from the list with filter_map.
So it would be worth asking in the SDK development Matrix room whether this is the best way to go about it, and whether it's OK to ignore errors here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for helping out. I've added your suggestion for now, and I will also ask quickly in the matrix room to see if we can find a better solution or if this is fine.
CodSpeed Performance ReportMerging #5953 will not alter performanceComparing Summary
|
Room::list_threads [help wanted]Room::list_threads
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5953 +/- ##
=======================================
Coverage 88.51% 88.51%
=======================================
Files 363 363
Lines 103432 103467 +35
Branches 103432 103467 +35
=======================================
+ Hits 91548 91585 +37
+ Misses 7531 7528 -3
- Partials 4353 4354 +1 ☔ View full report in Codecov by Sentry. |
Expose
Room::list_threadsto the FFI.I am new to this code base, so I'm trying to understand how all the pieces fit together.
I want to use
Room::list_threadsfrom Swift, so this pull request attempts to expose this function through the FFI.The code currently does not compile, because I don't know how to convert the SDK version of
TimelineEventobtained from theself.inner.list_threads(..), to a compatible FFI version.Can anyone with more experience guide me on what to do here?
Signed-off-by: Viktor Strate viktorstrate@gmail.com