Skip to content

refactor: Make SpaceRoom compute is_dm on demand#6561

Merged
jmartinesp merged 4 commits into
mainfrom
fix/tweak-space-room-is-dm
May 11, 2026
Merged

refactor: Make SpaceRoom compute is_dm on demand#6561
jmartinesp merged 4 commits into
mainfrom
fix/tweak-space-room-is-dm

Conversation

@jmartinesp

@jmartinesp jmartinesp commented May 11, 2026

Copy link
Copy Markdown
Contributor

This means making both SpaceRoom::new_from_summary and SpaceRoom::new_from_known_room async, which in turn forces us to change how we instantiate those in quite a few places.

Why do we need this? It seems like the pre-computed active_service_member_count is not usually available for these rooms: if you are in spaces with lots of rooms you haven't visited before, you wouldn't have triggered their sync_members call that would compute this value. In those cases, you'd get the wrong computed room display names and is_dm values.

Also, I tweaked a bit how the display name computation and the heroes values are returned:

  • The computed display name will try computing the joined service member count first now that we can do it, so that rooms with service members display the proper display name (i.e. in a room with you, Alice and a Bot service member it'll display simply 'Alice' instead of 'Alice, and 2 others', those 2 others being you and the bot). This happens because in compute_display_name_from_heroes the if num_heroes < num_joined_invited_except_self && num_joined_invited > 1 line would always be triggered for rooms with service members.
  • When using the heroes to compute the display name and when returning the heroes field in SpaceRoom, use Room::heroes instead of RoomInfo::heroes. The latter just stores what the HS returns, while the former filters out service members that should not be considered heroes.

Changes after review: the SpaceRoomList::rooms Mutex is now an AsyncMutex. This changes some other method signatures so they're async now too.

  • I've documented the public API Changes in the appropriate CHANGELOG.md files.
  • This PR was made with the help of AI.

Signed-off-by:

@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.08029% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.89%. Comparing base (58141e4) to head (7b2913c).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/matrix-sdk-ui/src/spaces/room.rs 76.47% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6561      +/-   ##
==========================================
- Coverage   89.93%   89.89%   -0.04%     
==========================================
  Files         381      381              
  Lines      106865   106886      +21     
  Branches   106865   106886      +21     
==========================================
- Hits        96112    96090      -22     
- Misses       7101     7132      +31     
- Partials     3652     3664      +12     

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

@jmartinesp jmartinesp marked this pull request as ready for review May 11, 2026 12:09
@jmartinesp jmartinesp requested a review from a team as a code owner May 11, 2026 12:09
@jmartinesp jmartinesp requested review from stefanceriu and removed request for a team May 11, 2026 12:09
@codspeed-hq

codspeed-hq Bot commented May 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing fix/tweak-space-room-is-dm (7b2913c) with main (58141e4)

Open in CodSpeed

Comment thread crates/matrix-sdk-ui/src/spaces/mod.rs Outdated
}
}

async fn children_rooms(client: &Client, children: &[OwnedRoomId], graph: &SpaceGraph) -> Vec<SpaceRoom> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we call this children_space_rooms to make things just a bit clearer? Or maybe use children_ids, or both?

Comment thread crates/matrix-sdk-ui/src/spaces/room_list.rs Outdated
Comment thread crates/matrix-sdk-ui/src/spaces/room_list.rs Outdated
@jmartinesp

Copy link
Copy Markdown
Contributor Author

I think I handled all the feedback in 48740d1, let me know if something's missing.

@jmartinesp jmartinesp requested a review from stefanceriu May 11, 2026 13:09

@stefanceriu stefanceriu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test are not happy, but I am, 🐑🚀 it!

@jmartinesp jmartinesp force-pushed the fix/tweak-space-room-is-dm branch from 27aba4f to 7b2913c Compare May 11, 2026 14:23
@jmartinesp jmartinesp enabled auto-merge (rebase) May 11, 2026 14:39
@jmartinesp jmartinesp merged commit 2d8b3ce into main May 11, 2026
53 of 54 checks passed
@jmartinesp jmartinesp deleted the fix/tweak-space-room-is-dm branch May 11, 2026 14:40
@jmartinesp

Copy link
Copy Markdown
Contributor Author

Many thanks to @frebib for his help while testing this, including a corner case I completely missed 🙏 .

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