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

Copy over non-federatable trait on room upgrade #4530

Merged
merged 6 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/4530.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copy over room federation ability on room upgrade.
10 changes: 10 additions & 0 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ def clone_existing_room(
}
}

# Check if old room was non-federatable

# Get old room's create event
old_room_create_event = yield self.store.get_create_event_for_room(old_room_id)

# Check if the create event specified a non-federatable room
if not old_room_create_event.content.get("m.federate", True):
# If so, mark the new room as non-federatable as well
creation_content["m.federate"] = False

initial_state = dict()

# Replicate relevant room events
Expand Down
31 changes: 20 additions & 11 deletions synapse/storage/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from twisted.internet import defer

from synapse.api.constants import EventTypes
from synapse.api.errors import NotFoundError
from synapse.storage._base import SQLBaseStore
from synapse.storage.background_updates import BackgroundUpdateStore
from synapse.storage.engines import PostgresEngine
Expand Down Expand Up @@ -428,13 +427,9 @@ def get_room_version(self, room_id):
"""
# for now we do this by looking at the create event. We may want to cache this
# more intelligently in future.
state_ids = yield self.get_current_state_ids(room_id)
create_id = state_ids.get((EventTypes.Create, ""))

if not create_id:
raise NotFoundError("Unknown room %s" % (room_id))

create_event = yield self.get_event(create_id)
# Retrieve the room's create event
create_event = yield self.get_create_event_for_room(room_id)
defer.returnValue(create_event.content.get("room_version", "1"))

@defer.inlineCallbacks
Expand All @@ -448,18 +443,32 @@ def get_room_predecessor(self, room_id):
Returns:
Deferred[unicode|None]: predecessor room id
"""
# Retrieve the room's create event
create_event = yield self.get_create_event_for_room(room_id)

# Return predecessor if present
defer.returnValue(create_event.content.get("predecessor", None))

@defer.inlineCallbacks
def get_create_event_for_room(self, room_id):
"""Get the create state event for a room.

Args:
room_id (str)

Returns:
Deferred[EventBase|None]: The room creation event. None if can not be found
"""
state_ids = yield self.get_current_state_ids(room_id)
create_id = state_ids.get((EventTypes.Create, ""))

# If we can't find the create event, assume we've hit a dead end
if not create_id:
defer.returnValue(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be possible to get here. Suggest you throw the NotFoundEvent (and update the docstring accordingly)


# Retrieve the room's create event
# Retrieve the room's create event and return
create_event = yield self.get_event(create_id)

# Return predecessor if present
defer.returnValue(create_event.content.get("predecessor", None))
defer.returnValue(create_event)

@cached(max_entries=100000, iterable=True)
def get_current_state_ids(self, room_id):
Expand Down