Skip to content

Commit

Permalink
Wait for getting a Join in response to an invite/join dance.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Aug 21, 2014
1 parent d12a7c3 commit 1587ea2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions synapse/handlers/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ def __init__(self, hs):
self.notifier = hs.get_notifier()
self.room_lock = hs.get_room_lock_manager()
self.state_handler = hs.get_state_handler()
self.distributor = hs.get_distributor()
self.hs = hs
29 changes: 27 additions & 2 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
class FederationHandler(BaseHandler):

"""Handles events that originated from federation."""
def __init__(self, hs):
super(FederationHandler, self).__init__(hs)

self.distributor.observe(
"user_joined_room",
self._on_user_joined
)

self.waiting_for_join_list = {}

@log_function
@defer.inlineCallbacks
Expand Down Expand Up @@ -103,6 +112,13 @@ def on_receive(self, event, is_new_state, backfilled):
if not backfilled:
yield self.notifier.on_new_room_event(event, store_id)

if event.type == RoomMemberEvent.TYPE:
if event.membership == Membership.JOIN:
user = self.hs.parse_userid(event.target_user_id)
self.distributor.fire(
"user_joined_room", user=user, room_id=event.room_id
)


@log_function
@defer.inlineCallbacks
Expand Down Expand Up @@ -152,8 +168,10 @@ def do_invite_join(self, target_host, room_id, joinee, content):

yield federation.handle_new_event(new_event)

store_id = yield self.store.persist_event(new_event)
self.notifier.on_new_room_event(new_event, store_id)
# TODO (erikj): Time out here.
d = defer.Deferred()
self.waiting_for_join_list.setdefault((joinee, room_id), []).append(d)
yield d

try:
yield self.store.store_room(
Expand All @@ -166,3 +184,10 @@ def do_invite_join(self, target_host, room_id, joinee, content):


defer.returnValue(True)


@log_function
def _on_user_joined(self, user, room_id):
waiters = self.waiting_for_join_list.get((user.to_string(), room_id), [])
while waiters:
waiters.pop().callback(None)

0 comments on commit 1587ea2

Please sign in to comment.