Skip to content

Conversation

@viktorstrate
Copy link

@viktorstrate viktorstrate commented Dec 11, 2025

Expose Room::list_threads to 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_threads from 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 TimelineEvent obtained from the self.inner.list_threads(..), to a compatible FFI version.
Can anyone with more experience guide me on what to do here?

  • Public API changes documented in changelogs (optional)

Signed-off-by: Viktor Strate viktorstrate@gmail.com

Signed-off-by: viktorstrate <viktorstrate@gmail.com>
@viktorstrate viktorstrate requested a review from a team as a code owner December 11, 2025 12:30
@viktorstrate viktorstrate requested review from andybalaam and removed request for a team December 11, 2025 12:30
@viktorstrate viktorstrate marked this pull request as draft December 11, 2025 12:30
let roots = self.inner.list_threads(inner_opts).await?;

Ok(ThreadRoots {
chunk: roots.chunk.into_iter().map(|x| x.into()).collect(),
Copy link
Author

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

Copy link
Member

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.

Copy link
Author

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-hq
Copy link

codspeed-hq bot commented Dec 11, 2025

CodSpeed Performance Report

Merging #5953 will not alter performance

Comparing viktorstrate:ffi-list-threads (02584e2) with main (ce65317)

Summary

✅ 50 untouched

@viktorstrate viktorstrate changed the title FFI: implement Room::list_threads [help wanted] FFI: implement Room::list_threads Dec 12, 2025
@viktorstrate viktorstrate marked this pull request as ready for review December 12, 2025 12:12
@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.51%. Comparing base (2522a36) to head (02584e2).
⚠️ Report is 9 commits behind head on main.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants