Skip to content

feat(sdk): Spaces #5509

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

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft

feat(sdk): Spaces #5509

wants to merge 23 commits into from

Conversation

stefanceriu
Copy link
Member

@stefanceriu stefanceriu commented Aug 8, 2025

This series of patches introduces a top level UI oriented interface for interacting with spaces.

The SpaceService offers:

  • a method for retrieving one's top level joined_spaces and a subscribe_to_joined_spaces stream that automatically updates based on client activity
    • to do so the service builds a graph from all the m.space.parent and m.space.children state events it knows about, removing cycles and then only keeping parent spaces
  • a SpaceRoomList that can be used to interact with the rooms hierarchy endpoint and retrieve rooms referencing a certain parent
    • the room list is responsible for holding the pagination state as well as listening to client activity and automatically publishing room state updates through its subscribe_to_room_updates publisher (e.g. when joining one of the rooms)

Ongoing:

  • convert the publishers to use vector diffs
  • add documentation with examples

@stefanceriu stefanceriu force-pushed the stefan/spaces branch 2 times, most recently from 655477a to f52ebdb Compare August 8, 2025 12:02
Copy link

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 90.93407% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.61%. Comparing base (eefa9ff) to head (e8325fe).
⚠️ Report is 16 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...x-sdk-base/src/response_processors/state_events.rs 29.62% 0 Missing and 19 partials ⚠️
crates/matrix-sdk-ui/src/spaces/mod.rs 94.55% 16 Missing ⚠️
crates/matrix-sdk-ui/src/spaces/room_list.rs 91.75% 13 Missing and 3 partials ⚠️
crates/matrix-sdk-ui/src/spaces/graph.rs 94.82% 4 Missing and 2 partials ⚠️
crates/matrix-sdk/src/test_utils/mocks/mod.rs 91.48% 4 Missing ⚠️
crates/matrix-sdk-ui/src/spaces/room.rs 91.89% 0 Missing and 3 partials ⚠️
crates/matrix-sdk/src/room/mod.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5509      +/-   ##
==========================================
+ Coverage   88.57%   88.61%   +0.04%     
==========================================
  Files         340      344       +4     
  Lines       93690    94389     +699     
  Branches    93690    94389     +699     
==========================================
+ Hits        82989    83646     +657     
- Misses       6568     6602      +34     
- Partials     4133     4141       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Aug 8, 2025

CodSpeed Performance Report

Merging #5509 will not alter performance

Comparing stefan/spaces (e8325fe) with main (9601624)

Summary

✅ 31 untouched benchmarks

@stefanceriu stefanceriu force-pushed the stefan/spaces branch 3 times, most recently from eab6c0c to 0b14496 Compare August 11, 2025 13:07
Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First fast review. Keep going!

Comment on lines 54 to 70
let handle = tokio::spawn(async move {
pin_mut!(all_room_updates_receiver);

loop {
match all_room_updates_receiver.recv().await {
Ok(_) => {
let new_spaces = Self::joined_spaces_for(&client_clone);
if new_spaces != joined_spaces_clone.get() {
joined_spaces_clone.set(new_spaces);
}
}
Err(err) => {
error!("error when listening to room updates: {err}");
}
}
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful to use AbortOnDrop here, we don't want the task to be detached.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, isn't manually aborting it in Drop for SpaceService enough? 🤔

@stefanceriu stefanceriu force-pushed the stefan/spaces branch 2 times, most recently from 5024faa to a2a4ef8 Compare August 11, 2025 16:14
Copy link
Member

@pixlwave pixlwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only a review on the FFI layer, but looks great!. Can't wait to see it land 🔭

spacex-2-3537887872

@stefanceriu stefanceriu force-pushed the stefan/spaces branch 5 times, most recently from aff6435 to 8dc94da Compare August 12, 2025 13:06
@bnjbvr bnjbvr changed the title Spaces feat(sdk): Spaces Aug 14, 2025
@stefanceriu stefanceriu force-pushed the stefan/spaces branch 2 times, most recently from cde1a3d to e761648 Compare August 14, 2025 14:57
@pixlwave
Copy link
Member

Something weird is going on with the latest version, all of my joined_spaces have a children_count of 0.

There's a branch here if you want to test the updates with diffing:
https://github.com/element-hq/element-x-ios/tree/doug/sdk-space-service

@stefanceriu
Copy link
Member Author

Something weird is going on with the latest version, all of my joined_spaces have a children_count of 0.

There's a branch here if you want to test the updates with diffing: https://github.com/element-hq/element-x-ios/tree/doug/sdk-space-service

Went ahead and fixed the remaining issues with VectorDiffs, seems fine now on your branch. Thanks for testing!

…::joined_spaces` and its reactive counterpart
…states change i.e. they get joined or left.
…ted uniffi version

- automatic Arc inference was introduced in 0.27 and complement is using 0.25
…state events in the sliding sync required state as they're both required to build a full view of the space room hierarchy
…tions to correctly detect all the edges and be able to remove any cycles.

- cycle removing is done through DFS and keeping a list of visited nodes
…ption methods so it can be retained on the client side
…` responses and `SpaceServiceRoomList` instances
…tead automatically setup a client subscription when requesting the joined services subscription
…d components on both the UI and the FFI crates
…ned spaces and space room list subscriptions
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.

3 participants