Include invited rooms in the initial sync

This commit is contained in:
Mark Haines 2015-10-13 11:03:48 +01:00
parent f96b480670
commit ab9cf73258
2 changed files with 26 additions and 11 deletions

View File

@ -63,16 +63,10 @@ class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
class InvitedSyncResult(collections.namedtuple("InvitedSyncResult", [ class InvitedSyncResult(collections.namedtuple("InvitedSyncResult", [
"room_id", "room_id",
"invite_state", "invite",
])): ])):
__slots__ = [] __slots__ = []
def __nonzero__(self):
"""Make the result appear empty if there are no updates. This is used
to tell if room needs to be part of the sync result.
"""
return bool(self.invite_state)
class SyncResult(collections.namedtuple("SyncResult", [ class SyncResult(collections.namedtuple("SyncResult", [
"next_batch", # Token for the next sync "next_batch", # Token for the next sync
@ -166,6 +160,7 @@ class SyncHandler(BaseHandler):
) )
joined = [] joined = []
invited = []
for event in room_list: for event in room_list:
if event.membership == Membership.JOIN: if event.membership == Membership.JOIN:
room_sync = yield self.initial_sync_for_room( room_sync = yield self.initial_sync_for_room(
@ -173,15 +168,16 @@ class SyncHandler(BaseHandler):
) )
joined.append(room_sync) joined.append(room_sync)
elif event.membership == Membership.INVITE: elif event.membership == Membership.INVITE:
invite = yield self.store.get_event(event.event_id)
invited.append(InvitedSyncResult( invited.append(InvitedSyncResult(
room_id=event.room_id, room_id=event.room_id,
invited_state=[event], invite=invite,
) ))
defer.returnValue(SyncResult( defer.returnValue(SyncResult(
presence=presence, presence=presence,
joined=joined, joined=joined,
invited=[], invited=invited,
next_batch=now_token, next_batch=now_token,
)) ))

View File

@ -132,13 +132,17 @@ class SyncRestServlet(RestServlet):
sync_result.joined, filter, time_now, token_id sync_result.joined, filter, time_now, token_id
) )
invited = self.encode_invited(
sync_result.invited, filter, time_now, token_id
)
response_content = { response_content = {
"presence": self.encode_presence( "presence": self.encode_presence(
sync_result.presence, filter, time_now sync_result.presence, filter, time_now
), ),
"rooms": { "rooms": {
"joined": joined, "joined": joined,
"invited": {}, "invited": invited,
"archived": {}, "archived": {},
}, },
"next_batch": sync_result.next_batch.to_string(), "next_batch": sync_result.next_batch.to_string(),
@ -163,6 +167,21 @@ class SyncRestServlet(RestServlet):
return joined return joined
def encode_invited(self, rooms, filter, time_now, token_id):
invited = {}
for room in rooms:
invite = serialize_event(
room.invite, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_event_id,
)
invited_state = invite.get("unsigned", {}).pop("invite_room_state", [])
invited_state.append(invite)
invited[room.room_id] = {
"invite_state": { "events": invited_state }
}
return invited
@staticmethod @staticmethod
def encode_room(room, filter, time_now, token_id): def encode_room(room, filter, time_now, token_id):
event_map = {} event_map = {}