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

Commit

Permalink
Split out sending the room alias events from creating the alias so th…
Browse files Browse the repository at this point in the history
…at we can do them in the right point when creating a room
  • Loading branch information
Mark Haines committed Nov 18, 2014
1 parent c571dd4 commit a5b88c4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
18 changes: 6 additions & 12 deletions synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,11 @@ def create_association(self, user_id, room_alias, room_id, servers=None):
if not servers:
raise SynapseError(400, "Failed to get server list")

try:
yield self.store.create_room_alias_association(
room_alias,
room_id,
servers
)
except sqlite3.IntegrityError:
defer.returnValue("Already exists")

# TODO: Send the room event.
yield self._update_room_alias_events(user_id, room_id)
yield self.store.create_room_alias_association(
room_alias,
room_id,
servers
)

@defer.inlineCallbacks
def delete_association(self, user_id, room_alias):
Expand Down Expand Up @@ -136,7 +130,7 @@ def on_directory_query(self, args):
})

@defer.inlineCallbacks
def _update_room_alias_events(self, user_id, room_id):
def send_room_alias_update_event(self, user_id, room_id):
aliases = yield self.store.get_aliases_for_room(room_id)

event = self.event_factory.create_event(
Expand Down
17 changes: 10 additions & 7 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ def create_room(self, user_id, room_id, config):
if not room_id:
raise StoreError(500, "Couldn't generate a room ID.")

if room_alias:
directory_handler = self.hs.get_handlers().directory_handler
yield directory_handler.create_association(
user_id=user_id,
room_id=room_id,
room_alias=room_alias,
servers=[self.hs.hostname],
)

user = self.hs.parse_userid(user_id)
creation_events = self._create_events_for_new_room(
user, room_id, is_public=is_public
Expand Down Expand Up @@ -180,13 +189,7 @@ def handle_event(event):

if room_alias:
result["room_alias"] = room_alias.to_string()
directory_handler = self.hs.get_handlers().directory_handler
yield directory_handler.create_association(
user_id=user_id,
room_id=room_id,
room_alias=room_alias,
servers=[self.hs.hostname],
)
directory_handler.send_room_alias_update_event(user_id, room_id)

defer.returnValue(result)

Expand Down
4 changes: 3 additions & 1 deletion synapse/rest/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ def on_PUT(self, request, room_alias):
dir_handler = self.handlers.directory_handler

try:
user_id = user.to_string()
yield dir_handler.create_association(
user.to_string(), room_alias, room_id, servers
user_id, room_alias, room_id, servers
)
yield dir_handler.send_room_alias_update_event(user_id, room_id)
except SynapseError as e:
raise e
except:
Expand Down
19 changes: 12 additions & 7 deletions synapse/storage/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ def create_room_alias_association(self, room_alias, room_id, servers):
Returns:
Deferred
"""
yield self._simple_insert(
"room_aliases",
{
"room_alias": room_alias.to_string(),
"room_id": room_id,
},
)
try:
yield self._simple_insert(
"room_aliases",
{
"room_alias": room_alias.to_string(),
"room_id": room_id,
},
)
except sqlite3.IntegrityError:
raise SynapseError(
409, "Room alias %s already exists" % room_alias.to_string()
)

for server in servers:
# TODO(erikj): Fix this to bulk insert
Expand Down

0 comments on commit a5b88c4

Please sign in to comment.