matrix-org / matrix-org/matrix-rust-sdk
room.active_members_count is 0 in message event
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 500
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 106
Description
Hello,
It looks like `room.active_members_count()` can return 0 in a message handler, even after enumerating `members(ACTIVE)`
e.g. this piece of code:
```
match room.members(RoomMemberships::ACTIVE).await {
Ok(members) => {
info!(
"Room {:?} had {} member counts, array length {}",
room.display_name().await,
room.active_members_count(),
members.len()
);
```
in a handler for `OriginalSyncRoomMessageEvent` prints:
```
[2023-06-04T11:33:42Z INFO matrirc::matrix::room_mappings] Room Ok(Named("somerom")) had 0 member counts, array length 77
```
(as of last week's main branch, 623ff6fa8308 , but doesn't look like anything related got in since ; full code is here: https://github.com/martinetd/matrirc/commit/a7e516e0f9286dfdc51b337bc24a880980164420 -- it goes src/matrix/mod.rs 's `on_room_message` > src/matrix/room_mappings.rs `mappings().room_target(&room)` > `query_of_room` in same file; only the info! message is missing. This is a resumed session.)
I didn't see anything in the doc describing when the count is valid, are there rules about this?
The count comes from the summary values which should be updated by `update_summary`, and that looks like it should be done automatically when room info comes in, and that in turn looks like it should automatically come in as well but perhaps it came in after the message event in question?
For context, I wanted to use `room.active_members_count()` to discriminate between "queries" (direct messages) and "channels" (proper room) on my irc server as it looked like enumerating members can be slow and I sort of thought about delaying that enumeration in a separate task later.
(I'm aware of is_direct/direct_targets but in practice one could invite more people to a direct room, and rooms with just two people also make just as much sense to treat as query in my opinion)
In practice there isn't such a big difference in delaying the enumeration, so I'll just be using members.len() directly for now, but this got me curious.
Thanks!
Contributor guide
Research direction
Start with src/matrix/mod.rs at on_room_message, then follow room_mappings.rs through mappings().room_target(&room) and query_of_room. Inspect how update_summary and room information events relate to the message event, using the reported resumed-session sequence as context. Done means establishing when active_members_count() is valid and documenting or correcting the observed zero value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100