Prevent showing non-fed rooms in fed /publicRooms#4736
Prevent showing non-fed rooms in fed /publicRooms#4736anoadragon453 merged 15 commits intodevelopfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #4736 +/- ##
===========================================
- Coverage 75.14% 75.09% -0.06%
===========================================
Files 340 340
Lines 34826 34861 +35
Branches 5704 5711 +7
===========================================
+ Hits 26170 26178 +8
- Misses 7046 7071 +25
- Partials 1610 1612 +2 |
richvdh
left a comment
There was a problem hiding this comment.
generally looks pretty sane, though I am led to the question of why you would ever want to set this option to True?
| search_filter=None, | ||
| network_tuple=EMPTY_THIRD_PARTY_ID,): | ||
| network_tuple=EMPTY_THIRD_PARTY_ID, | ||
| from_federation=False): |
synapse/handlers/room_list.py
Outdated
|
|
||
| Args: | ||
| room_id (str): The room's ID. | ||
| disabled should be shown. |
synapse/handlers/room_list.py
Outdated
| if result["m.federate"] == False: | ||
| # This is a non-federating room and the config has chosen not | ||
| # to show these rooms to other servers | ||
| chunk.append(None) |
There was a problem hiding this comment.
The original code was returning None and then appending it to the chunk, so I kept doing so. Not sure if it's necessary or we can just leave it out.
There was a problem hiding this comment.
Looking at the code, I don't think Nones in there are particularly useful, so just not inserting anything (by returning instead) seems like the right way to go.
synapse/handlers/room_list.py
Outdated
|
|
||
| if result and _matches_room_entry(result, search_filter): | ||
| if from_federation and not self.config.allow_non_federated_in_public_rooms: | ||
| if result["m.federate"] == False: |
There was a problem hiding this comment.
result may be None. Suggest adding
if not result:
return
synapse/handlers/room_list.py
Outdated
| search_filter=None, | ||
| network_tuple=EMPTY_THIRD_PARTY_ID, | ||
| timeout=None,): | ||
| from_federation=False, timeout=None,): |
There was a problem hiding this comment.
| from_federation=False, timeout=None,): | |
| from_federation=False, | |
| timeout=None, | |
| ): |
(or whatever the right alignment for the closing paren is with this style)
| @defer.inlineCallbacks | ||
| def _append_room_entry_to_chunk(self, room_id, num_joined_users, chunk, limit, | ||
| search_filter): | ||
| search_filter, from_federation=False): |
There was a problem hiding this comment.
docstring for from_federation wouldn't hurt.
synapse/handlers/room_list.py
Outdated
| """Generate a public room list. | ||
|
|
||
| Args: | ||
| limit (int): Maximum amount of rooms to return. |
synapse/handlers/room_list.py
Outdated
|
|
||
| Args: | ||
| limit (int): Maximum amount of rooms to return. | ||
| since_token (str) |
synapse/handlers/room_list.py
Outdated
| Args: | ||
| limit (int): Maximum amount of rooms to return. | ||
| since_token (str) | ||
| search_filter (dict): Dictionary to filter rooms by. |
synapse/handlers/room_list.py
Outdated
| Setting to None returns all public rooms across all lists. | ||
| from_federation (bool): Whether this request originated from a | ||
| federating server or a client. Used for room filtering. | ||
| timeout (int): Amount of seconds to wait for a response before |
| to the `chunk` if it matches the search filter | ||
|
|
||
| Args: | ||
| room_id (str): The ID of the room. |
There was a problem hiding this comment.
Again, if you're going to add these, please get the types right
There was a problem hiding this comment.
synapse/synapse/storage/state.py
Line 486 in 40c2271
Are they supposed to be RoomIDs?
There was a problem hiding this comment.
Ah, you meant adding |None. Have done so for the other types yes.
synapse/handlers/room_list.py
Outdated
|
|
||
| if from_federation and not self.config.allow_non_federated_in_public_rooms: | ||
| if result["m.federate"] == False: | ||
| if not result or result["m.federate"] is False: |
There was a problem hiding this comment.
not result["m.federate"] is clearer
There was a problem hiding this comment.
The problem was that if "m.federate" wasn't in result, it would imply a federating room.
I've realized this logic doesn't cover that and could lead to a crash, and thus have replaced with:
if from_federation:
if "m.federate" in result and not result["m.federate"]:
# This is a room that other servers cannot join. Do not show them
# this room.
return
There was a problem hiding this comment.
well, m.federate will always be present in this case afaict.
However, for the record, what you want to handle the case you mention is if not result.get("m.federate", True).
Also, consider merging it with the other if: if from_federation and result...
There was a problem hiding this comment.
Yep, split it up as two ands was getting unclean. This is cleaner though, thank you.
synapse/handlers/room_list.py
Outdated
| num_joined_users) | ||
| result = yield self.generate_room_entry(room_id, num_joined_users) | ||
|
|
||
| if from_federation and not self.config.allow_non_federated_in_public_rooms: |
There was a problem hiding this comment.
unless I'm completely misreading this, it will never do anything if from_federation is true.
I still suggest adding:
if not result:
return
before looking at from_federation or whatever.
|
\ooooooooooooo/ |
Replaces #4714