@@ -149,7 +149,9 @@ def upgrade_room(
149149 return ret
150150
151151 @defer .inlineCallbacks
152- def _upgrade_room (self , requester , old_room_id , new_version ):
152+ def _upgrade_room (
153+ self , requester : Requester , old_room_id : str , new_version : RoomVersion
154+ ):
153155 user_id = requester .user .to_string ()
154156
155157 # start by allocating a new room id
@@ -448,19 +450,21 @@ def clone_existing_room(
448450
449451 @defer .inlineCallbacks
450452 def _move_aliases_to_new_room (
451- self , requester , old_room_id , new_room_id , old_room_state
453+ self ,
454+ requester : Requester ,
455+ old_room_id : str ,
456+ new_room_id : str ,
457+ old_room_state : StateMap [str ],
452458 ):
453459 directory_handler = self .hs .get_handlers ().directory_handler
454460
455461 aliases = yield self .store .get_aliases_for_room (old_room_id )
456462
457463 # check to see if we have a canonical alias.
458- canonical_alias = None
464+ canonical_alias_event = None
459465 canonical_alias_event_id = old_room_state .get ((EventTypes .CanonicalAlias , "" ))
460466 if canonical_alias_event_id :
461467 canonical_alias_event = yield self .store .get_event (canonical_alias_event_id )
462- if canonical_alias_event :
463- canonical_alias = canonical_alias_event .content .get ("alias" , "" )
464468
465469 # first we try to remove the aliases from the old room (we suppress sending
466470 # the room_aliases event until the end).
@@ -488,19 +492,6 @@ def _move_aliases_to_new_room(
488492 if not removed_aliases :
489493 return
490494
491- try :
492- # this can fail if, for some reason, our user doesn't have perms to send
493- # m.room.aliases events in the old room (note that we've already checked that
494- # they have perms to send a tombstone event, so that's not terribly likely).
495- #
496- # If that happens, it's regrettable, but we should carry on: it's the same
497- # as when you remove an alias from the directory normally - it just means that
498- # the aliases event gets out of sync with the directory
499- # (cf https://github.com/vector-im/riot-web/issues/2369)
500- yield directory_handler .send_room_alias_update_event (requester , old_room_id )
501- except AuthError as e :
502- logger .warning ("Failed to send updated alias event on old room: %s" , e )
503-
504495 # we can now add any aliases we successfully removed to the new room.
505496 for alias in removed_aliases :
506497 try :
@@ -517,21 +508,21 @@ def _move_aliases_to_new_room(
517508 # checking module decides it shouldn't, or similar.
518509 logger .error ("Error adding alias %s to new room: %s" , alias , e )
519510
511+ # If a canonical alias event existed for the old room, fire a canonical
512+ # alias event for the new room with a copy of the information.
520513 try :
521- if canonical_alias and ( canonical_alias in removed_aliases ) :
514+ if canonical_alias_event :
522515 yield self .event_creation_handler .create_and_send_nonmember_event (
523516 requester ,
524517 {
525518 "type" : EventTypes .CanonicalAlias ,
526519 "state_key" : "" ,
527520 "room_id" : new_room_id ,
528521 "sender" : requester .user .to_string (),
529- "content" : { "alias" : canonical_alias } ,
522+ "content" : canonical_alias_event . content ,
530523 },
531524 ratelimit = False ,
532525 )
533-
534- yield directory_handler .send_room_alias_update_event (requester , new_room_id )
535526 except SynapseError as e :
536527 # again I'm not really expecting this to fail, but if it does, I'd rather
537528 # we returned the new room to the client at this point.
@@ -757,7 +748,6 @@ def create_room(self, requester, config, ratelimit=True, creator_join_profile=No
757748
758749 if room_alias :
759750 result ["room_alias" ] = room_alias .to_string ()
760- yield directory_handler .send_room_alias_update_event (requester , room_id )
761751
762752 return result
763753
0 commit comments