mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-07-27 08:15:26 -04:00
Include heroes in partial join responses' state (#14442)
* Pull out hero selection logic * Include heroes in partial join response's state * Changelog * Fixup trial test * Remove TODO
This commit is contained in:
parent
258b5285b6
commit
1eed795fc5
5 changed files with 60 additions and 25 deletions
|
@ -1517,6 +1517,36 @@ class RoomMemberStore(
|
|||
await self.db_pool.runInteraction("forget_membership", f)
|
||||
|
||||
|
||||
def extract_heroes_from_room_summary(
|
||||
details: Mapping[str, MemberSummary], me: str
|
||||
) -> List[str]:
|
||||
"""Determine the users that represent a room, from the perspective of the `me` user.
|
||||
|
||||
The rules which say which users we select are specified in the "Room Summary"
|
||||
section of
|
||||
https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3sync
|
||||
|
||||
Returns a list (possibly empty) of heroes' mxids.
|
||||
"""
|
||||
empty_ms = MemberSummary([], 0)
|
||||
|
||||
joined_user_ids = [
|
||||
r[0] for r in details.get(Membership.JOIN, empty_ms).members if r[0] != me
|
||||
]
|
||||
invited_user_ids = [
|
||||
r[0] for r in details.get(Membership.INVITE, empty_ms).members if r[0] != me
|
||||
]
|
||||
gone_user_ids = [
|
||||
r[0] for r in details.get(Membership.LEAVE, empty_ms).members if r[0] != me
|
||||
] + [r[0] for r in details.get(Membership.BAN, empty_ms).members if r[0] != me]
|
||||
|
||||
# FIXME: order by stream ordering rather than as returned by SQL
|
||||
if joined_user_ids or invited_user_ids:
|
||||
return sorted(joined_user_ids + invited_user_ids)[0:5]
|
||||
else:
|
||||
return sorted(gone_user_ids)[0:5]
|
||||
|
||||
|
||||
@attr.s(slots=True, auto_attribs=True)
|
||||
class _JoinedHostsCache:
|
||||
"""The cached data used by the `_get_joined_hosts_cache`."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue