-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support MSC3266 room summaries over federation #11507
Changes from 6 commits
2dcb306
946ac90
3269f1e
9543837
7d4bafd
96c848d
51e6374
10ac986
c8ae763
9f5ef27
cbb58f2
6ff9873
1318e6b
433a394
87bcc6f
0184eac
a92d936
5481e11
a0fb144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. |
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,7 @@ 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 +659,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,8 +715,12 @@ 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"], | ||
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. In some situations this could potentially fix the hack on L656-657 about assuming We should guard these with the unstable config flag, probably? 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 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 commentThe 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 commentThe 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 |
||
} | ||
|
||
if stats["encryption"]: | ||
entry["im.nheko.summary.encryption"] = stats["encryption"] | ||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Federation requests need to provide additional information so the | ||
# requested server is able to filter the response appropriately. | ||
if for_federation: | ||
|
@@ -812,15 +818,50 @@ 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 | ||
# and allowed_spaces keys. | ||
room.pop("allowed_room_ids", None) | ||
room.pop("allowed_spaces", None) | ||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# A remote room can't be in the joined state | ||
room["membership"] = "leave" | ||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return room | ||
|
||
raise NotFoundError("Room not found or is not accessible") | ||
|
||
return room_summary | ||
|
||
|
||
@attr.s(frozen=True, slots=True, auto_attribs=True) | ||
class _RoomQueueEntry: | ||
|
||
deepbluev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# The room ID of this entry. | ||
room_id: str | ||
# The server to query if the room is not known locally. | ||
|
Uh oh!
There was an error while loading. Please reload this page.