forked from MirrorHub/synapse
Update the v2 room sync format to match the current v2 spec
This commit is contained in:
parent
e3d3205cd9
commit
dfef2b41aa
2 changed files with 18 additions and 21 deletions
|
@ -165,8 +165,7 @@ class SyncHandler(BaseHandler):
|
||||||
))
|
))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def initial_sync_for_room(self, room_id, sync_config, now_token,
|
def initial_sync_for_room(self, room_id, sync_config, now_token):
|
||||||
published_room_ids):
|
|
||||||
"""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 RoomSyncResult.
|
||||||
|
@ -230,10 +229,6 @@ class SyncHandler(BaseHandler):
|
||||||
sync_config.user
|
sync_config.user
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO (mjark): Does public mean "published"?
|
|
||||||
published_rooms = yield self.store.get_rooms(is_public=True)
|
|
||||||
published_room_ids = set(r["room_id"] for r in published_rooms)
|
|
||||||
|
|
||||||
timeline_limit = sync_config.filter.timeline_limit()
|
timeline_limit = sync_config.filter.timeline_limit()
|
||||||
|
|
||||||
room_events, _ = yield self.store.get_room_events_stream(
|
room_events, _ = yield self.store.get_room_events_stream(
|
||||||
|
@ -268,11 +263,12 @@ class SyncHandler(BaseHandler):
|
||||||
|
|
||||||
room_sync = RoomSyncResult(
|
room_sync = RoomSyncResult(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
published=room_id in published_room_ids,
|
timeline=TimelineBatch(
|
||||||
events=recents,
|
events=recents,
|
||||||
prev_batch=prev_batch,
|
prev_batch=prev_batch,
|
||||||
|
limited=False,
|
||||||
|
),
|
||||||
state=state,
|
state=state,
|
||||||
limited=False,
|
|
||||||
ephemeral=typing_by_room.get(room_id, [])
|
ephemeral=typing_by_room.get(room_id, [])
|
||||||
)
|
)
|
||||||
if room_sync:
|
if room_sync:
|
||||||
|
@ -344,11 +340,11 @@ class SyncHandler(BaseHandler):
|
||||||
limited = True
|
limited = True
|
||||||
recents = []
|
recents = []
|
||||||
filtering_factor = 2
|
filtering_factor = 2
|
||||||
load_limit = max(sync_config.limit * filtering_factor, 100)
|
timeline_limit = sync_config.filter.timeline_limit()
|
||||||
|
load_limit = max(timeline_limit * filtering_factor, 100)
|
||||||
max_repeat = 3 # Only try a few times per room, otherwise
|
max_repeat = 3 # Only try a few times per room, otherwise
|
||||||
room_key = now_token.room_key
|
room_key = now_token.room_key
|
||||||
end_key = room_key
|
end_key = room_key
|
||||||
timeline_limit = sync_config.filter.timeline_limit()
|
|
||||||
|
|
||||||
while limited and len(recents) < timeline_limit and max_repeat:
|
while limited and len(recents) < timeline_limit and max_repeat:
|
||||||
events, keys = yield self.store.get_recent_events_for_room(
|
events, keys = yield self.store.get_recent_events_for_room(
|
||||||
|
@ -369,8 +365,9 @@ class SyncHandler(BaseHandler):
|
||||||
limited = False
|
limited = False
|
||||||
max_repeat -= 1
|
max_repeat -= 1
|
||||||
|
|
||||||
if len(recents) > sync_config.limit:
|
if len(recents) > timeline_limit:
|
||||||
recents = recents[-sync_config.limit:]
|
limited = True
|
||||||
|
recents = recents[-timeline_limit:]
|
||||||
room_key = recents[0].internal_metadata.before
|
room_key = recents[0].internal_metadata.before
|
||||||
|
|
||||||
prev_batch_token = now_token.copy_and_replace(
|
prev_batch_token = now_token.copy_and_replace(
|
||||||
|
|
|
@ -158,7 +158,7 @@ class SyncRestServlet(RestServlet):
|
||||||
def encode_room(room, filter, time_now, token_id):
|
def encode_room(room, filter, time_now, token_id):
|
||||||
event_map = {}
|
event_map = {}
|
||||||
state_events = filter.filter_room_state(room.state)
|
state_events = filter.filter_room_state(room.state)
|
||||||
recent_events = filter.filter_room_events(room.events)
|
recent_events = filter.filter_room_events(room.timeline.events)
|
||||||
state_event_ids = []
|
state_event_ids = []
|
||||||
recent_event_ids = []
|
recent_event_ids = []
|
||||||
for event in state_events:
|
for event in state_events:
|
||||||
|
@ -178,13 +178,13 @@ class SyncRestServlet(RestServlet):
|
||||||
recent_event_ids.append(event.event_id)
|
recent_event_ids.append(event.event_id)
|
||||||
result = {
|
result = {
|
||||||
"event_map": event_map,
|
"event_map": event_map,
|
||||||
"events": {
|
"timeline": {
|
||||||
"batch": recent_event_ids,
|
"events": recent_event_ids,
|
||||||
"prev_batch": room.prev_batch.to_string(),
|
"prev_batch": room.timeline.prev_batch.to_string(),
|
||||||
|
"limited": room.timeline.limited,
|
||||||
},
|
},
|
||||||
"state": state_event_ids,
|
"state": {"events": state_event_ids},
|
||||||
"limited": room.limited,
|
"ephemeral": {"events": room.ephemeral},
|
||||||
"ephemeral": room.ephemeral,
|
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue