mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Start spliting out the rooms into joined and invited in v2 sync
This commit is contained in:
parent
586beb8318
commit
956509dfec
@ -46,7 +46,7 @@ class TimelineBatch(collections.namedtuple("TimelineBatch", [
|
|||||||
return bool(self.events)
|
return bool(self.events)
|
||||||
|
|
||||||
|
|
||||||
class RoomSyncResult(collections.namedtuple("RoomSyncResult", [
|
class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
||||||
"room_id",
|
"room_id",
|
||||||
"timeline",
|
"timeline",
|
||||||
"state",
|
"state",
|
||||||
@ -61,10 +61,24 @@ class RoomSyncResult(collections.namedtuple("RoomSyncResult", [
|
|||||||
return bool(self.timeline or self.state or self.ephemeral)
|
return bool(self.timeline or self.state or self.ephemeral)
|
||||||
|
|
||||||
|
|
||||||
|
class InvitedSyncResult(collections.namedtuple("InvitedSyncResult", [
|
||||||
|
"room_id",
|
||||||
|
"invite_state",
|
||||||
|
])):
|
||||||
|
__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
|
||||||
"presence", # List of presence events for the user.
|
"presence", # List of presence events for the user.
|
||||||
"rooms", # RoomSyncResult for each room.
|
"joined", # JoinedSyncResult for each joined room.
|
||||||
|
"invited", # InvitedSyncResult for each invited room.
|
||||||
])):
|
])):
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
|
|
||||||
@ -151,24 +165,31 @@ class SyncHandler(BaseHandler):
|
|||||||
membership_list=[Membership.INVITE, Membership.JOIN]
|
membership_list=[Membership.INVITE, Membership.JOIN]
|
||||||
)
|
)
|
||||||
|
|
||||||
rooms = []
|
joined = []
|
||||||
for event in room_list:
|
for event in room_list:
|
||||||
|
if event.membership == Membership.JOIN:
|
||||||
room_sync = yield self.initial_sync_for_room(
|
room_sync = yield self.initial_sync_for_room(
|
||||||
event.room_id, sync_config, now_token,
|
event.room_id, sync_config, now_token,
|
||||||
)
|
)
|
||||||
rooms.append(room_sync)
|
joined.append(room_sync)
|
||||||
|
elif event.membership == Membership.INVITE:
|
||||||
|
invited.append(InvitedSyncResult(
|
||||||
|
room_id=event.room_id,
|
||||||
|
invited_state=[event],
|
||||||
|
)
|
||||||
|
|
||||||
defer.returnValue(SyncResult(
|
defer.returnValue(SyncResult(
|
||||||
presence=presence,
|
presence=presence,
|
||||||
rooms=rooms,
|
joined=joined,
|
||||||
|
invited=[],
|
||||||
next_batch=now_token,
|
next_batch=now_token,
|
||||||
))
|
))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def initial_sync_for_room(self, room_id, sync_config, now_token):
|
def initial_sync_for_joined_room(self, room_id, sync_config, now_token):
|
||||||
"""Sync a room for a client which is starting without any state
|
"""Sync a room for a client which is starting without any state
|
||||||
Returns:
|
Returns:
|
||||||
A Deferred RoomSyncResult.
|
A Deferred JoinedSyncResult.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
batch = yield self.load_filtered_recents(
|
batch = yield self.load_filtered_recents(
|
||||||
@ -180,7 +201,7 @@ class SyncHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
current_state_events = current_state.values()
|
current_state_events = current_state.values()
|
||||||
|
|
||||||
defer.returnValue(RoomSyncResult(
|
defer.returnValue(JoinedSyncResult(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
timeline=batch,
|
timeline=batch,
|
||||||
state=current_state_events,
|
state=current_state_events,
|
||||||
@ -239,7 +260,7 @@ class SyncHandler(BaseHandler):
|
|||||||
limit=timeline_limit + 1,
|
limit=timeline_limit + 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
rooms = []
|
joined = []
|
||||||
if len(room_events) <= timeline_limit:
|
if len(room_events) <= timeline_limit:
|
||||||
# There is no gap in any of the rooms. Therefore we can just
|
# There is no gap in any of the rooms. Therefore we can just
|
||||||
# partition the new events by room and return them.
|
# partition the new events by room and return them.
|
||||||
@ -261,7 +282,7 @@ class SyncHandler(BaseHandler):
|
|||||||
sync_config, room_id, state
|
sync_config, room_id, state
|
||||||
)
|
)
|
||||||
|
|
||||||
room_sync = RoomSyncResult(
|
room_sync = JoinedSyncResult(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
timeline=TimelineBatch(
|
timeline=TimelineBatch(
|
||||||
events=recents,
|
events=recents,
|
||||||
@ -272,7 +293,7 @@ class SyncHandler(BaseHandler):
|
|||||||
ephemeral=typing_by_room.get(room_id, [])
|
ephemeral=typing_by_room.get(room_id, [])
|
||||||
)
|
)
|
||||||
if room_sync:
|
if room_sync:
|
||||||
rooms.append(room_sync)
|
joined.append(room_sync)
|
||||||
else:
|
else:
|
||||||
for room_id in room_ids:
|
for room_id in room_ids:
|
||||||
room_sync = yield self.incremental_sync_with_gap_for_room(
|
room_sync = yield self.incremental_sync_with_gap_for_room(
|
||||||
@ -280,11 +301,12 @@ class SyncHandler(BaseHandler):
|
|||||||
typing_by_room
|
typing_by_room
|
||||||
)
|
)
|
||||||
if room_sync:
|
if room_sync:
|
||||||
rooms.append(room_sync)
|
joined.append(room_sync)
|
||||||
|
|
||||||
defer.returnValue(SyncResult(
|
defer.returnValue(SyncResult(
|
||||||
presence=presence,
|
presence=presence,
|
||||||
rooms=rooms,
|
joined=joined,
|
||||||
|
invited=[],
|
||||||
next_batch=now_token,
|
next_batch=now_token,
|
||||||
))
|
))
|
||||||
|
|
||||||
@ -386,7 +408,7 @@ class SyncHandler(BaseHandler):
|
|||||||
the room. Gives the client the most recent events and the changes to
|
the room. Gives the client the most recent events and the changes to
|
||||||
state.
|
state.
|
||||||
Returns:
|
Returns:
|
||||||
A Deferred RoomSyncResult
|
A Deferred JoinedSyncResult
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO(mjark): Check for redactions we might have missed.
|
# TODO(mjark): Check for redactions we might have missed.
|
||||||
@ -418,7 +440,7 @@ class SyncHandler(BaseHandler):
|
|||||||
sync_config, room_id, state_events_delta
|
sync_config, room_id, state_events_delta
|
||||||
)
|
)
|
||||||
|
|
||||||
room_sync = RoomSyncResult(
|
room_sync = JoinedSyncResult(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
timeline=batch,
|
timeline=batch,
|
||||||
state=state_events_delta,
|
state=state_events_delta,
|
||||||
|
@ -128,15 +128,19 @@ class SyncRestServlet(RestServlet):
|
|||||||
|
|
||||||
time_now = self.clock.time_msec()
|
time_now = self.clock.time_msec()
|
||||||
|
|
||||||
rooms = self.encode_rooms(
|
joined = self.encode_joined(
|
||||||
sync_result.rooms, filter, time_now, token_id
|
sync_result.joined, 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,
|
"rooms": {
|
||||||
|
"joined": joined,
|
||||||
|
"invited": {},
|
||||||
|
"archived": {},
|
||||||
|
},
|
||||||
"next_batch": sync_result.next_batch.to_string(),
|
"next_batch": sync_result.next_batch.to_string(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,18 +154,14 @@ class SyncRestServlet(RestServlet):
|
|||||||
formatted.append(event)
|
formatted.append(event)
|
||||||
return {"events": filter.filter_presence(formatted)}
|
return {"events": filter.filter_presence(formatted)}
|
||||||
|
|
||||||
def encode_rooms(self, rooms, filter, time_now, token_id):
|
def encode_joined(self, rooms, filter, time_now, token_id):
|
||||||
joined = {}
|
joined = {}
|
||||||
for room in rooms:
|
for room in rooms:
|
||||||
joined[room.room_id] = self.encode_room(
|
joined[room.room_id] = self.encode_room(
|
||||||
room, filter, time_now, token_id
|
room, filter, time_now, token_id
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return joined
|
||||||
"joined": joined,
|
|
||||||
"invited": {},
|
|
||||||
"archived": {},
|
|
||||||
}
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def encode_room(room, filter, time_now, token_id):
|
def encode_room(room, filter, time_now, token_id):
|
||||||
|
Loading…
Reference in New Issue
Block a user