0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-30 14:33:54 +01:00

Transfer alias mappings when joining an upgraded room (#6946)

This commit is contained in:
Andrew Morgan 2020-03-30 17:53:25 +01:00 committed by GitHub
parent d9f29f8dae
commit 7042840b32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 3 deletions

1
changelog.d/6946.bugfix Normal file
View file

@ -0,0 +1 @@
Transfer alias mappings on room upgrade.

View file

@ -519,6 +519,9 @@ class RoomMemberHandler(object):
yield self.store.set_room_is_public(old_room_id, False) yield self.store.set_room_is_public(old_room_id, False)
yield self.store.set_room_is_public(room_id, True) yield self.store.set_room_is_public(room_id, True)
# Transfer alias mappings in the room directory
yield self.store.update_aliases_for_room(old_room_id, room_id)
# Check if any groups we own contain the predecessor room # Check if any groups we own contain the predecessor room
local_group_ids = yield self.store.get_local_groups_for_room(old_room_id) local_group_ids = yield self.store.get_local_groups_for_room(old_room_id)
for group_id in local_group_ids: for group_id in local_group_ids:

View file

@ -14,6 +14,7 @@
# limitations under the License. # limitations under the License.
from collections import namedtuple from collections import namedtuple
from typing import Optional
from twisted.internet import defer from twisted.internet import defer
@ -159,10 +160,29 @@ class DirectoryStore(DirectoryWorkerStore):
return room_id return room_id
def update_aliases_for_room(self, old_room_id, new_room_id, creator): def update_aliases_for_room(
self, old_room_id: str, new_room_id: str, creator: Optional[str] = None,
):
"""Repoint all of the aliases for a given room, to a different room.
Args:
old_room_id:
new_room_id:
creator: The user to record as the creator of the new mapping.
If None, the creator will be left unchanged.
"""
def _update_aliases_for_room_txn(txn): def _update_aliases_for_room_txn(txn):
sql = "UPDATE room_aliases SET room_id = ?, creator = ? WHERE room_id = ?" update_creator_sql = ""
txn.execute(sql, (new_room_id, creator, old_room_id)) sql_params = (new_room_id, old_room_id)
if creator:
update_creator_sql = ", creator = ?"
sql_params = (new_room_id, creator, old_room_id)
sql = "UPDATE room_aliases SET room_id = ? %s WHERE room_id = ?" % (
update_creator_sql,
)
txn.execute(sql, sql_params)
self._invalidate_cache_and_stream( self._invalidate_cache_and_stream(
txn, self.get_aliases_for_room, (old_room_id,) txn, self.get_aliases_for_room, (old_room_id,)
) )