WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@viktorstrate
Copy link

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 [email protected]

@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.

@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 (b2a31df) with main (9a6acd5)

Summary

✅ 50 untouched

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