-
Notifications
You must be signed in to change notification settings - Fork 345
Add is_encrypted
filtering to Sliding Sync /sync
#17281
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
Merged
MadLittleMods
merged 30 commits into
develop
from
madlittlemods/msc3575-sliding-sync-filter-encrypted2
Jun 17, 2024
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
76ce7a9
Add `is_dm` filtering to Sliding Sync `/sync`
MadLittleMods 360f05c
Move changelog
MadLittleMods d8e2b1d
Add docstring
MadLittleMods dd43938
Reference actual filter code
MadLittleMods 88fe201
Condense true/false tests
MadLittleMods 44088bd
Add `is_encrypted` filtering to Sliding Sync `/sync`
MadLittleMods 4412dbd
Update changelog number
MadLittleMods 35b18be
Fix lints
MadLittleMods 61f86e0
Add future todo
MadLittleMods 578b44a
Move get_state_at() to area we can share from
MadLittleMods 7dec930
Filter based on state at to_token
MadLittleMods 945197b
Update docstring
MadLittleMods 48eca7d
Less test bulk
MadLittleMods 7aa0519
Incorporate `to_token` to filters
MadLittleMods a6e5798
Explain why no `to_token` for global account data
MadLittleMods 5dd6d37
Add docstring
MadLittleMods d0d198f
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-filter…
MadLittleMods 271ae6f
Remove import workaround
MadLittleMods 2e4627b
Merge branch 'madlittlemods/msc3575-sliding-sync-filter-dms' into mad…
MadLittleMods 355de36
Remove import workaround
MadLittleMods f69d1c5
Remove sneaky log
MadLittleMods bb5dfc3
Merge branch 'madlittlemods/msc3575-sliding-sync-filter-dms' into mad…
MadLittleMods d752b8a
Comment no longer as useful
MadLittleMods 9896478
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-filter…
MadLittleMods eaaf408
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-filter…
MadLittleMods aff2e82
Merge branch 'madlittlemods/msc3575-sliding-sync-filter-dms' into mad…
MadLittleMods 0ea4fdd
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-filter…
MadLittleMods 810e9af
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-filter…
MadLittleMods 8965f3b
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-filter…
MadLittleMods c73391d
Fix tests
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add `is_encrypted` filtering to experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -979,91 +979,6 @@ async def _load_filtered_recents( | |
bundled_aggregations=bundled_aggregations, | ||
) | ||
|
||
async def get_state_after_event( | ||
self, | ||
event_id: str, | ||
state_filter: Optional[StateFilter] = None, | ||
await_full_state: bool = True, | ||
) -> StateMap[str]: | ||
""" | ||
Get the room state after the given event | ||
|
||
Args: | ||
event_id: event of interest | ||
state_filter: The state filter used to fetch state from the database. | ||
await_full_state: if `True`, will block if we do not yet have complete state | ||
at the event and `state_filter` is not satisfied by partial state. | ||
Defaults to `True`. | ||
""" | ||
state_ids = await self._state_storage_controller.get_state_ids_for_event( | ||
event_id, | ||
state_filter=state_filter or StateFilter.all(), | ||
await_full_state=await_full_state, | ||
) | ||
|
||
# using get_metadata_for_events here (instead of get_event) sidesteps an issue | ||
# with redactions: if `event_id` is a redaction event, and we don't have the | ||
# original (possibly because it got purged), get_event will refuse to return | ||
# the redaction event, which isn't terribly helpful here. | ||
# | ||
# (To be fair, in that case we could assume it's *not* a state event, and | ||
# therefore we don't need to worry about it. But still, it seems cleaner just | ||
# to pull the metadata.) | ||
m = (await self.store.get_metadata_for_events([event_id]))[event_id] | ||
if m.state_key is not None and m.rejection_reason is None: | ||
state_ids = dict(state_ids) | ||
state_ids[(m.event_type, m.state_key)] = event_id | ||
|
||
return state_ids | ||
|
||
async def get_state_at( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving |
||
self, | ||
room_id: str, | ||
stream_position: StreamToken, | ||
state_filter: Optional[StateFilter] = None, | ||
await_full_state: bool = True, | ||
) -> StateMap[str]: | ||
"""Get the room state at a particular stream position | ||
|
||
Args: | ||
room_id: room for which to get state | ||
stream_position: point at which to get state | ||
state_filter: The state filter used to fetch state from the database. | ||
await_full_state: if `True`, will block if we do not yet have complete state | ||
at the last event in the room before `stream_position` and | ||
`state_filter` is not satisfied by partial state. Defaults to `True`. | ||
""" | ||
# FIXME: This gets the state at the latest event before the stream ordering, | ||
# which might not be the same as the "current state" of the room at the time | ||
# of the stream token if there were multiple forward extremities at the time. | ||
last_event_id = ( | ||
await self.store.get_last_event_id_in_room_before_stream_ordering( | ||
room_id, | ||
end_token=stream_position.room_key, | ||
) | ||
) | ||
|
||
if last_event_id: | ||
state = await self.get_state_after_event( | ||
last_event_id, | ||
state_filter=state_filter or StateFilter.all(), | ||
await_full_state=await_full_state, | ||
) | ||
|
||
else: | ||
# no events in this room - so presumably no state | ||
state = {} | ||
|
||
# (erikj) This should be rarely hit, but we've had some reports that | ||
# we get more state down gappy syncs than we should, so let's add | ||
# some logging. | ||
logger.info( | ||
"Failed to find any events in room %s at %s", | ||
room_id, | ||
stream_position.room_key, | ||
) | ||
return state | ||
|
||
async def compute_summary( | ||
self, | ||
room_id: str, | ||
|
@@ -1437,7 +1352,7 @@ async def _compute_state_delta_for_full_sync( | |
await_full_state = True | ||
lazy_load_members = False | ||
|
||
state_at_timeline_end = await self.get_state_at( | ||
state_at_timeline_end = await self._state_storage_controller.get_state_at( | ||
room_id, | ||
stream_position=end_token, | ||
state_filter=state_filter, | ||
|
@@ -1565,7 +1480,7 @@ async def _compute_state_delta_for_incremental_sync( | |
else: | ||
# We can get here if the user has ignored the senders of all | ||
# the recent events. | ||
state_at_timeline_start = await self.get_state_at( | ||
state_at_timeline_start = await self._state_storage_controller.get_state_at( | ||
room_id, | ||
stream_position=end_token, | ||
state_filter=state_filter, | ||
|
@@ -1587,14 +1502,14 @@ async def _compute_state_delta_for_incremental_sync( | |
# about them). | ||
state_filter = StateFilter.all() | ||
|
||
state_at_previous_sync = await self.get_state_at( | ||
state_at_previous_sync = await self._state_storage_controller.get_state_at( | ||
room_id, | ||
stream_position=since_token, | ||
state_filter=state_filter, | ||
await_full_state=await_full_state, | ||
) | ||
|
||
state_at_timeline_end = await self.get_state_at( | ||
state_at_timeline_end = await self._state_storage_controller.get_state_at( | ||
room_id, | ||
stream_position=end_token, | ||
state_filter=state_filter, | ||
|
@@ -2593,7 +2508,7 @@ async def _get_room_changes_for_incremental_sync( | |
continue | ||
|
||
if room_id in sync_result_builder.joined_room_ids or has_join: | ||
old_state_ids = await self.get_state_at( | ||
old_state_ids = await self._state_storage_controller.get_state_at( | ||
room_id, | ||
since_token, | ||
state_filter=StateFilter.from_types([(EventTypes.Member, user_id)]), | ||
|
@@ -2623,12 +2538,14 @@ async def _get_room_changes_for_incremental_sync( | |
newly_left_rooms.append(room_id) | ||
else: | ||
if not old_state_ids: | ||
old_state_ids = await self.get_state_at( | ||
room_id, | ||
since_token, | ||
state_filter=StateFilter.from_types( | ||
[(EventTypes.Member, user_id)] | ||
), | ||
old_state_ids = ( | ||
await self._state_storage_controller.get_state_at( | ||
room_id, | ||
since_token, | ||
state_filter=StateFilter.from_types( | ||
[(EventTypes.Member, user_id)] | ||
), | ||
) | ||
) | ||
old_mem_ev_id = old_state_ids.get( | ||
(EventTypes.Member, user_id), None | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.