Merge remote-tracking branch 'upstream/release-v1.61'

This commit is contained in:
Tulir Asokan 2022-06-14 13:54:26 +03:00
commit 1543a3643e
235 changed files with 5079 additions and 14896 deletions

View file

@ -20,7 +20,7 @@ from typing_extensions import Final
from synapse.api.constants import EventTypes, HistoryVisibility, Membership
from synapse.events import EventBase
from synapse.events.utils import prune_event
from synapse.storage import Storage
from synapse.storage.controllers import StorageControllers
from synapse.storage.state import StateFilter
from synapse.types import RetentionPolicy, StateMap, get_domain_from_id
@ -47,7 +47,7 @@ _HISTORY_VIS_KEY: Final[Tuple[str, str]] = (EventTypes.RoomHistoryVisibility, ""
async def filter_events_for_client(
storage: Storage,
storage: StorageControllers,
user_id: str,
events: List[EventBase],
is_peeking: bool = False,
@ -170,16 +170,7 @@ async def filter_events_for_client(
state = event_id_to_state[event.event_id]
# get the room_visibility at the time of the event.
visibility_event = state.get(_HISTORY_VIS_KEY, None)
if visibility_event:
visibility = visibility_event.content.get(
"history_visibility", HistoryVisibility.SHARED
)
else:
visibility = HistoryVisibility.SHARED
if visibility not in VISIBILITY_PRIORITY:
visibility = HistoryVisibility.SHARED
visibility = get_effective_room_visibility_from_state(state)
# Always allow history visibility events on boundaries. This is done
# by setting the effective visibility to the least restrictive
@ -275,8 +266,25 @@ async def filter_events_for_client(
return [ev for ev in filtered_events if ev]
def get_effective_room_visibility_from_state(state: StateMap[EventBase]) -> str:
"""Get the actual history vis, from a state map including the history_visibility event
Handles missing and invalid history visibility events.
"""
visibility_event = state.get(_HISTORY_VIS_KEY, None)
if not visibility_event:
return HistoryVisibility.SHARED
visibility = visibility_event.content.get(
"history_visibility", HistoryVisibility.SHARED
)
if visibility not in VISIBILITY_PRIORITY:
visibility = HistoryVisibility.SHARED
return visibility
async def filter_events_for_server(
storage: Storage,
storage: StorageControllers,
server_name: str,
events: List[EventBase],
redact: bool = True,
@ -368,7 +376,7 @@ async def filter_events_for_server(
async def _event_to_history_vis(
storage: Storage, events: Collection[EventBase]
storage: StorageControllers, events: Collection[EventBase]
) -> Dict[str, str]:
"""Get the history visibility at each of the given events
@ -415,7 +423,7 @@ async def _event_to_history_vis(
async def _event_to_memberships(
storage: Storage, events: Collection[EventBase], server_name: str
storage: StorageControllers, events: Collection[EventBase], server_name: str
) -> Dict[str, StateMap[EventBase]]:
"""Get the remote membership list at each of the given events