-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Prevent showing non-fed rooms in fed /publicRooms #4736
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 |
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.
generally looks pretty sane, though I am led to the question of why you would ever want to set this option to True?
|
||
def get_local_public_room_list(self, limit=None, since_token=None, | ||
search_filter=None, | ||
network_tuple=EMPTY_THIRD_PARTY_ID,): | ||
network_tuple=EMPTY_THIRD_PARTY_ID, | ||
from_federation=False): |
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.
docstring pls
synapse/handlers/room_list.py
Outdated
|
||
Args: | ||
room_id (str): The room's ID. | ||
disabled should be shown. |
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.
?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we not just pass
?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code, I don't think None
s in there are particularly useful, so just not inserting anything (by return
ing 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result may be None. Suggest adding
if not result:
return
synapse/handlers/room_list.py
Outdated
) | ||
|
||
@defer.inlineCallbacks | ||
def _get_public_room_list(self, limit=None, since_token=None, | ||
search_filter=None, | ||
network_tuple=EMPTY_THIRD_PARTY_ID, | ||
timeout=None,): | ||
from_federation=False, timeout=None,): |
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.
from_federation=False, timeout=None,): | |
from_federation=False, | |
timeout=None, | |
): |
(or whatever the right alignment for the closing paren is with this style)
@@ -288,23 +292,41 @@ def get_order_for_room(room_id): | |||
|
|||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.
int|None
synapse/handlers/room_list.py
Outdated
|
||
Args: | ||
limit (int): Maximum amount of rooms to return. | ||
since_token (str) |
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.
str|None
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. |
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.
dict|None
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 |
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.
int|None
@@ -295,19 +311,28 @@ def _append_room_entry_to_chunk(self, room_id, num_joined_users, chunk, limit, | |||
search_filter, from_federation=False): | |||
"""Generate the entry for a room in the public room list and append it | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, if you're going to add these, please get the types right
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.
synapse/synapse/storage/state.py
Line 486 in 40c2271
room_id (str) |
Are they supposed to be RoomID
s?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not result["m.federate"]
is clearer
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, split it up as two and
s was getting unclean. This is cleaner though, thank you.
synapse/handlers/room_list.py
Outdated
""" | ||
if limit and len(chunk) > limit + 1: | ||
# We've already got enough, so lets just drop it. | ||
return | ||
|
||
result = yield self.generate_room_entry(room_id, | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
lgtm \o/
\ooooooooooooo/ |
Replaces #4714