mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 04:15:03 -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
|
@ -74,6 +74,8 @@ from synapse.replication.http.federation import (
|
|||
)
|
||||
from synapse.storage.databases.main.events import PartialStateConflictError
|
||||
from synapse.storage.databases.main.lock import Lock
|
||||
from synapse.storage.databases.main.roommember import extract_heroes_from_room_summary
|
||||
from synapse.storage.roommember import MemberSummary
|
||||
from synapse.types import JsonDict, StateMap, get_domain_from_id
|
||||
from synapse.util import json_decoder, unwrapFirstError
|
||||
from synapse.util.async_helpers import Linearizer, concurrently_execute, gather_results
|
||||
|
@ -691,8 +693,9 @@ class FederationServer(FederationBase):
|
|||
state_event_ids: Collection[str]
|
||||
servers_in_room: Optional[Collection[str]]
|
||||
if caller_supports_partial_state:
|
||||
summary = await self.store.get_room_summary(room_id)
|
||||
state_event_ids = _get_event_ids_for_partial_state_join(
|
||||
event, prev_state_ids
|
||||
event, prev_state_ids, summary
|
||||
)
|
||||
servers_in_room = await self.state.get_hosts_in_room_at_events(
|
||||
room_id, event_ids=event.prev_event_ids()
|
||||
|
@ -1495,6 +1498,7 @@ class FederationHandlerRegistry:
|
|||
def _get_event_ids_for_partial_state_join(
|
||||
join_event: EventBase,
|
||||
prev_state_ids: StateMap[str],
|
||||
summary: Dict[str, MemberSummary],
|
||||
) -> Collection[str]:
|
||||
"""Calculate state to be retuned in a partial_state send_join
|
||||
|
||||
|
@ -1521,8 +1525,19 @@ def _get_event_ids_for_partial_state_join(
|
|||
if current_membership_event_id is not None:
|
||||
state_event_ids.add(current_membership_event_id)
|
||||
|
||||
# TODO: return a few more members:
|
||||
# - those with invites
|
||||
# - those that are kicked? / banned
|
||||
name_id = prev_state_ids.get((EventTypes.Name, ""))
|
||||
canonical_alias_id = prev_state_ids.get((EventTypes.CanonicalAlias, ""))
|
||||
if not name_id and not canonical_alias_id:
|
||||
# Also include the hero members of the room (for DM rooms without a title).
|
||||
# To do this properly, we should select the correct subset of membership events
|
||||
# from `prev_state_ids`. Instead, we are lazier and use the (cached)
|
||||
# `get_room_summary` function, which is based on the current state of the room.
|
||||
# This introduces races; we choose to ignore them because a) they should be rare
|
||||
# and b) even if it's wrong, joining servers will get the full state eventually.
|
||||
heroes = extract_heroes_from_room_summary(summary, join_event.state_key)
|
||||
for hero in heroes:
|
||||
membership_event_id = prev_state_ids.get((EventTypes.Member, hero))
|
||||
if membership_event_id:
|
||||
state_event_ids.add(membership_event_id)
|
||||
|
||||
return state_event_ids
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue