This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support MSC3266 room summaries over federation #11507
Merged
squahtx
merged 19 commits into
matrix-org:develop
from
deepbluev7:nico/room-summary-federation
May 5, 2022
Merged
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2dcb306
Support MSC3266 room summaries over federation
deepbluev7 946ac90
Add changelog
deepbluev7 3269f1e
Update synapse/handlers/room_summary.py
deepbluev7 9543837
Update to not use the deprecated summary federation API
deepbluev7 7d4bafd
Add encryption to summary
deepbluev7 96c848d
Add room version field
deepbluev7 51e6374
Don't manually exclude summary fields
deepbluev7 10ac986
Apply suggestions from code review
deepbluev7 c8ae763
Add basic federation test for room summaries
deepbluev7 9f5ef27
fedroom -> fed_room
deepbluev7 cbb58f2
Fix remote room membership handling
deepbluev7 6ff9873
Update synapse/handlers/room_summary.py
deepbluev7 1318e6b
Don't overwrite cache entry by accident
deepbluev7 433a394
Remove redundant room_id check
deepbluev7 87bcc6f
Add assert for returned hierarchy response to federation client
deepbluev7 0184eac
Move additional parameters in /hierarchy response behind unstable flag
deepbluev7 a92d936
Update synapse/federation/federation_client.py
deepbluev7 5481e11
Invert logic of room summary handler to reduce indentation
deepbluev7 a0fb144
Reflow comments
deepbluev7 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 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 @@ | ||
Support [MSC3266](https://github.com/matrix-org/matrix-doc/pull/3266) room summaries over federation. |
This file contains 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 |
---|---|---|
|
@@ -630,7 +630,7 @@ async def _is_local_room_accessible( | |
return False | ||
|
||
async def _is_remote_room_accessible( | ||
self, requester: str, room_id: str, room: JsonDict | ||
self, requester: Optional[str], room_id: str, room: JsonDict | ||
) -> bool: | ||
""" | ||
Calculate whether the room received over federation should be shown to the requester. | ||
|
@@ -645,7 +645,8 @@ async def _is_remote_room_accessible( | |
due to an invite, etc. | ||
|
||
Args: | ||
requester: The user requesting the summary. | ||
requester: The user requesting the summary. If not passed only world | ||
readability is checked. | ||
room_id: The room ID returned over federation. | ||
room: The summary of the room returned over federation. | ||
|
||
|
@@ -659,6 +660,8 @@ async def _is_remote_room_accessible( | |
or room.get("world_readable") is True | ||
): | ||
return True | ||
elif not requester: | ||
return False | ||
|
||
# Check if the user is a member of any of the allowed rooms from the response. | ||
allowed_rooms = room.get("allowed_room_ids") | ||
|
@@ -713,6 +716,8 @@ async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDic | |
), | ||
"guest_can_join": stats["guest_access"] == "can_join", | ||
"room_type": create_event.content.get(EventContentFields.ROOM_TYPE), | ||
"im.nheko.summary.version": stats["version"], | ||
"im.nheko.summary.encryption": stats["encryption"], | ||
} | ||
|
||
# Federation requests need to provide additional information so the | ||
|
@@ -812,9 +817,51 @@ async def get_room_summary( | |
|
||
room_summary["membership"] = membership or "leave" | ||
else: | ||
# TODO federation API, descoped from initial unstable implementation | ||
# as MSC needs more maturing on that side. | ||
raise SynapseError(400, "Federation is not currently supported.") | ||
# Reuse the hierarchy query over federation | ||
if remote_room_hosts is None: | ||
raise SynapseError(400, "Missing via to query remote room") | ||
|
||
( | ||
room_entry, | ||
children_room_entries, | ||
inaccessible_children, | ||
) = await self._summarize_remote_room_hierarchy( | ||
_RoomQueueEntry(room_id, remote_room_hosts), | ||
suggested_only=True, | ||
) | ||
|
||
if room_entry: | ||
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. I'm finding the level of indentation here rather difficult to follow. It could be nicer to check 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. I've inverted the logic now and combined the 2 if cases, which gets rid of 2 levels of indentation. If I don't combine them I would have to duplicate the error messages, because I want the error to be the same for inaccessible or not found. |
||
room = room_entry.room | ||
fed_room_id = room_entry.room_id | ||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if fed_room_id == room_id: | ||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# The results over federation might include rooms that the we, | ||
# as the requesting server, are allowed to see, but the requesting | ||
# user is not permitted to see. | ||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Filter the returned results to only what is accessible to the user. | ||
if await self._is_remote_room_accessible( | ||
requester, fed_room_id, room | ||
): | ||
# Before returning to the client, remove the allowed_room_ids | ||
# key. | ||
room.pop("allowed_room_ids", None) | ||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# If there was a requester, add their membership. | ||
# We keep the membership in the local membership table | ||
# unless the room is purged even for remote rooms. | ||
if requester: | ||
( | ||
membership, | ||
_, | ||
) = await self._store.get_local_current_membership_for_user_in_room( | ||
requester, room_id | ||
) | ||
room["membership"] = membership or "leave" | ||
|
||
return room | ||
|
||
raise NotFoundError("Room not found or is not accessible") | ||
|
||
return room_summary | ||
|
||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some situations this could potentially fix the hack on L656-657 about assuming
knock
is valid. Would probably not be available often enough though.We should guard these with the unstable config flag, probably?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should wait for this to be stable first and available for a while and then we can use that to fix the hack, since we need the remote server to use it. After a few months it is probably safe to just assume a room is version 1, if no version is returned.
I think an unstable flag would probably make more sense for the whole feature instead of just some namespaced fields. I was hoping the MSC just FCPs and passes in the next few weeks, since it is quite small and then we can just stabilize it (so I don't need to figure out how to add unstable flags :D). But I'll defer that to your judgement. If you want a flag, I can add it. I am just lazy .-.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already is one for the whole feature -- I'm suggesting to re-use it and guard these fields with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think I figured it out. I cache the flag in the Handler, as it doesn't cache the hs yet and I think just caching the flag makes more sense? No idea :D