Skip to content

Commit 46de0ee

Browse files
Sliding Sync: Update filters to be robust against remote invite rooms (#17450)
Update `filters.is_encrypted` and `filters.types`/`filters.not_types` to be robust when dealing with remote invite rooms in Sliding Sync. Part of [MSC3575](matrix-org/matrix-spec-proposals#3575): Sliding Sync Follow-up to #17434 We now take into account current state, fallback to stripped state for invite/knock rooms, then historical state. If we can't determine the info needed to filter a room (either from state or stripped state), it is filtered out.
1 parent b221f0b commit 46de0ee

File tree

11 files changed

+1598
-110
lines changed

11 files changed

+1598
-110
lines changed

changelog.d/17450.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint to handle invite/knock rooms when filtering.

synapse/api/constants.py

+8
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ class EventContentFields:
225225
# This is deprecated in MSC2175.
226226
ROOM_CREATOR: Final = "creator"
227227

228+
# The version of the room for `m.room.create` events.
229+
ROOM_VERSION: Final = "room_version"
230+
231+
ROOM_NAME: Final = "name"
232+
228233
# Used in m.room.guest_access events.
229234
GUEST_ACCESS: Final = "guest_access"
230235

@@ -237,6 +242,9 @@ class EventContentFields:
237242
# an unspecced field added to to-device messages to identify them uniquely-ish
238243
TO_DEVICE_MSGID: Final = "org.matrix.msgid"
239244

245+
# `m.room.encryption`` algorithm field
246+
ENCRYPTION_ALGORITHM: Final = "algorithm"
247+
240248

241249
class EventUnsignedContentFields:
242250
"""Fields found inside the 'unsigned' data on events"""

synapse/events/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,22 @@ def relation_from_event(event: EventBase) -> Optional[_EventRelation]:
554554
aggregation_key = None
555555

556556
return _EventRelation(parent_id, rel_type, aggregation_key)
557+
558+
559+
@attr.s(slots=True, frozen=True, auto_attribs=True)
560+
class StrippedStateEvent:
561+
"""
562+
A stripped down state event. Usually used for remote invite/knocks so the user can
563+
make an informed decision on whether they want to join.
564+
565+
Attributes:
566+
type: Event `type`
567+
state_key: Event `state_key`
568+
sender: Event `sender`
569+
content: Event `content`
570+
"""
571+
572+
type: str
573+
state_key: str
574+
sender: str
575+
content: Dict[str, Any]

synapse/events/utils.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from synapse.api.room_versions import RoomVersion
5050
from synapse.types import JsonDict, Requester
5151

52-
from . import EventBase, make_event_from_dict
52+
from . import EventBase, StrippedStateEvent, make_event_from_dict
5353

5454
if TYPE_CHECKING:
5555
from synapse.handlers.relations import BundledAggregations
@@ -854,3 +854,30 @@ def strip_event(event: EventBase) -> JsonDict:
854854
"content": event.content,
855855
"sender": event.sender,
856856
}
857+
858+
859+
def parse_stripped_state_event(raw_stripped_event: Any) -> Optional[StrippedStateEvent]:
860+
"""
861+
Given a raw value from an event's `unsigned` field, attempt to parse it into a
862+
`StrippedStateEvent`.
863+
"""
864+
if isinstance(raw_stripped_event, dict):
865+
# All of these fields are required
866+
type = raw_stripped_event.get("type")
867+
state_key = raw_stripped_event.get("state_key")
868+
sender = raw_stripped_event.get("sender")
869+
content = raw_stripped_event.get("content")
870+
if (
871+
isinstance(type, str)
872+
and isinstance(state_key, str)
873+
and isinstance(sender, str)
874+
and isinstance(content, dict)
875+
):
876+
return StrippedStateEvent(
877+
type=type,
878+
state_key=state_key,
879+
sender=sender,
880+
content=content,
881+
)
882+
883+
return None

0 commit comments

Comments
 (0)