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

Commit 99eed85

Browse files
authored
Do not send alias events when creating / upgrading a room (#6941)
Stop emitting room alias update events during room creation/upgrade.
1 parent a90d0dc commit 99eed85

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

changelog.d/6941.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stop sending m.room.aliases events during room creation and upgrade.

synapse/handlers/directory.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616

17+
import collections
1718
import logging
1819
import string
1920
from typing import List
@@ -282,22 +283,6 @@ def on_directory_query(self, args):
282283
Codes.NOT_FOUND,
283284
)
284285

285-
@defer.inlineCallbacks
286-
def send_room_alias_update_event(self, requester, room_id):
287-
aliases = yield self.store.get_aliases_for_room(room_id)
288-
289-
yield self.event_creation_handler.create_and_send_nonmember_event(
290-
requester,
291-
{
292-
"type": EventTypes.Aliases,
293-
"state_key": self.hs.hostname,
294-
"room_id": room_id,
295-
"sender": requester.user.to_string(),
296-
"content": {"aliases": aliases},
297-
},
298-
ratelimit=False,
299-
)
300-
301286
@defer.inlineCallbacks
302287
def _update_canonical_alias(self, requester, user_id, room_id, room_alias):
303288
"""
@@ -326,7 +311,7 @@ def _update_canonical_alias(self, requester, user_id, room_id, room_alias):
326311
alt_aliases = content.pop("alt_aliases", None)
327312
# If the aliases are not a list (or not found) do not attempt to modify
328313
# the list.
329-
if isinstance(alt_aliases, list):
314+
if isinstance(alt_aliases, collections.Sequence):
330315
send_update = True
331316
alt_aliases = [alias for alias in alt_aliases if alias != alias_str]
332317
if alt_aliases:

synapse/handlers/room.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)