Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Prevent message search in upgraded rooms we're not in #6385

Merged
merged 11 commits into from
Dec 11, 2019
1 change: 1 addition & 0 deletions changelog.d/6385.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent error on trying to search a upgraded room when the server is not in the predecessor room.
13 changes: 12 additions & 1 deletion synapse/handlers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ class SearchHandler(BaseHandler):
def __init__(self, hs):
super(SearchHandler, self).__init__(hs)
self._event_serializer = hs.get_event_client_serializer()
self.hs = hs
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.auth = hs.get_auth()

@defer.inlineCallbacks
def get_old_rooms_from_upgraded_room(self, room_id):
Expand Down Expand Up @@ -65,8 +67,17 @@ def get_old_rooms_from_upgraded_room(self, room_id):
if not predecessor:
break

predecessor_room_id = predecessor["room_id"]
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

# Don't bother trying to search in rooms we're not in
in_room = yield self.auth.check_host_in_room(
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
predecessor_room_id, self.hs.hostname
)
if not in_room:
break

# Add predecessor's room ID
historical_room_ids.append(predecessor["room_id"])
historical_room_ids.append(predecessor_room_id)
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

# Scan through the old room for further predecessors
room_id = predecessor["room_id"]
Expand Down