Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding Sync: Update filters to be robust against remote invite rooms #17450

Merged
merged 51 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3a6eec1
Make `filters.is_encrypted` robust to remote invites
MadLittleMods Jul 15, 2024
7f72d80
Try share work
MadLittleMods Jul 15, 2024
18ec437
More robust
MadLittleMods Jul 15, 2024
a67157e
Fix lints
MadLittleMods Jul 15, 2024
ffb61cf
Return bool from db
MadLittleMods Jul 15, 2024
9b77c97
Add tests
MadLittleMods Jul 16, 2024
d609205
Standardize
MadLittleMods Jul 16, 2024
8ca8ae5
Add TODO for more tests
MadLittleMods Jul 16, 2024
4f50054
Add changelog
MadLittleMods Jul 16, 2024
7ae2425
Invalidate caches
MadLittleMods Jul 16, 2024
b35a2da
Use `ROOM_UNKNOWN_SENTINEL`
MadLittleMods Jul 16, 2024
4bb34d3
Iterate on sentinels
MadLittleMods Jul 16, 2024
a07ee22
Simply sentinel for now
MadLittleMods Jul 16, 2024
2c9ec61
Merge branch 'develop' into madlittlemods/robust-remote-invite-filters
MadLittleMods Jul 16, 2024
27a97a0
fetch -> get
MadLittleMods Jul 16, 2024
517bfc4
Update comments
MadLittleMods Jul 16, 2024
d22bae4
Fix typo
MadLittleMods Jul 16, 2024
8624fb0
Better docstring
MadLittleMods Jul 16, 2024
a77b70e
Use constants
MadLittleMods Jul 16, 2024
df5093b
Prefer not implementing if not used
MadLittleMods Jul 18, 2024
7c33c83
Separate to its own function (`_bulk_get_stripped_state_for_rooms` ->…
MadLittleMods Jul 18, 2024
474b480
Use `StateMap`
MadLittleMods Jul 18, 2024
82fa037
Fix function name in assertion message
MadLittleMods Jul 18, 2024
6f05bb3
Add tests for when the server leaves the room
MadLittleMods Jul 18, 2024
d4c4de1
Ideally, not just current state
MadLittleMods Jul 18, 2024
0ace82d
Add `test_filter_encrypted_after_we_left`
MadLittleMods Jul 18, 2024
8c97eaa
Try get server left rooms (not working)
MadLittleMods Jul 19, 2024
8dd5a47
Implement `is_local_host_in_rooms(...)`
MadLittleMods Jul 19, 2024
5267b03
Start of join room_stats_current
MadLittleMods Jul 19, 2024
329bf09
Working `room_stats_state` joined by `room_stats_current.local_users_…
MadLittleMods Jul 19, 2024
d7dcbfd
Add corresponding tests for `filter.room_types`
MadLittleMods Jul 19, 2024
60ec4e3
Fix some lints
MadLittleMods Jul 19, 2024
affee22
Fix lints
MadLittleMods Jul 19, 2024
8ee1708
Explain why we join tables
MadLittleMods Jul 19, 2024
fe2d84b
Use `StrippedStateEvent` type in tests
MadLittleMods Jul 19, 2024
4ae3079
Prefer f-string
MadLittleMods Jul 22, 2024
05bbcb0
Add `_bulk_get_partial_current_state_content_for_rooms_from_sync_room…
MadLittleMods Jul 23, 2024
376d900
Simplify and share
MadLittleMods Jul 23, 2024
28a36e8
Remove unused methods
MadLittleMods Jul 23, 2024
ac7ca67
Maybe current state in the future
MadLittleMods Jul 23, 2024
15e157e
Fix cache busting
MadLittleMods Jul 23, 2024
19968e1
Fix lints
MadLittleMods Jul 23, 2024
8f5e4bf
Shorten name
MadLittleMods Jul 23, 2024
3c144b3
Reconsider all stripped events
MadLittleMods Jul 23, 2024
f3b4c9f
Merge branch 'develop' into madlittlemods/robust-remote-invite-filters
MadLittleMods Jul 23, 2024
1732b02
Prefer cache invalidation helper
MadLittleMods Jul 23, 2024
20902e6
Merge branch 'develop' into madlittlemods/robust-remote-invite-filters
MadLittleMods Jul 25, 2024
e9b76cc
Go back to dedicated `room_stats_state` lookups
MadLittleMods Jul 25, 2024
484007e
Update cache busting
MadLittleMods Jul 25, 2024
7acb1ad
Prefer `assert_never`
MadLittleMods Jul 30, 2024
45ed4ce
Merge branch 'develop' into madlittlemods/robust-remote-invite-filters
MadLittleMods Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/17450.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update experimental [MSC3575](https:/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint to handle invite/knock rooms when filtering.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, wonder if its worth worrying too much about the encrypted filter? Not sure anyone actually uses it?

-- @erikjohnston, #17450 (comment)

The is_encrypted filter and room_types filter both share the same challenges in fetching room state so solving one isn't more work than the other.

We will also need to apply these patterns for the other filters like room_name_like so figuring out how to share the work between filters also makes sense.

We're going to implement these other filters at some point anyway.

8 changes: 8 additions & 0 deletions synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ class EventContentFields:
# This is deprecated in MSC2175.
ROOM_CREATOR: Final = "creator"

# The version of the room for `m.room.create` events.
ROOM_VERSION: Final = "room_version"

ROOM_NAME: Final = "name"

# Used in m.room.guest_access events.
GUEST_ACCESS: Final = "guest_access"

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

# `m.room.encryption`` algorithm field
ENCRYPTION_ALGORITHM: Final = "algorithm"


class EventUnsignedContentFields:
"""Fields found inside the 'unsigned' data on events"""
Expand Down
19 changes: 19 additions & 0 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,22 @@ def relation_from_event(event: EventBase) -> Optional[_EventRelation]:
aggregation_key = None

return _EventRelation(parent_id, rel_type, aggregation_key)


@attr.s(slots=True, frozen=True, auto_attribs=True)
class StrippedStateEvent:
"""
A stripped down state event. Usually used for remote invite/knocks so the user can
make an informed decision on whether they want to join.

Attributes:
type: Event `type`
state_key: Event `state_key`
sender: Event `sender`
content: Event `content`
"""

type: str
state_key: str
sender: str
content: Dict[str, Any]
29 changes: 28 additions & 1 deletion synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from synapse.api.room_versions import RoomVersion
from synapse.types import JsonDict, Requester

from . import EventBase, make_event_from_dict
from . import EventBase, StrippedStateEvent, make_event_from_dict

if TYPE_CHECKING:
from synapse.handlers.relations import BundledAggregations
Expand Down Expand Up @@ -854,3 +854,30 @@ def strip_event(event: EventBase) -> JsonDict:
"content": event.content,
"sender": event.sender,
}


def parse_stripped_state_event(raw_stripped_event: Any) -> Optional[StrippedStateEvent]:
"""
Given a raw value from an event's `unsigned` field, attempt to parse it into a
`StrippedStateEvent`.
"""
if isinstance(raw_stripped_event, dict):
# All of these fields are required
type = raw_stripped_event.get("type")
state_key = raw_stripped_event.get("state_key")
sender = raw_stripped_event.get("sender")
content = raw_stripped_event.get("content")
if (
isinstance(type, str)
and isinstance(state_key, str)
and isinstance(sender, str)
and isinstance(content, dict)
):
return StrippedStateEvent(
type=type,
state_key=state_key,
sender=sender,
content=content,
)

return None
Loading
Loading