Update the v2 room sync format to match the current v2 spec

This commit is contained in:
Mark Haines 2015-10-08 15:17:43 +01:00
parent e3d3205cd9
commit dfef2b41aa
2 changed files with 18 additions and 21 deletions

View file

@ -165,8 +165,7 @@ class SyncHandler(BaseHandler):
))
@defer.inlineCallbacks
def initial_sync_for_room(self, room_id, sync_config, now_token,
published_room_ids):
def initial_sync_for_room(self, room_id, sync_config, now_token):
"""Sync a room for a client which is starting without any state
Returns:
A Deferred RoomSyncResult.
@ -230,10 +229,6 @@ class SyncHandler(BaseHandler):
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()
room_events, _ = yield self.store.get_room_events_stream(
@ -268,11 +263,12 @@ class SyncHandler(BaseHandler):
room_sync = RoomSyncResult(
room_id=room_id,
published=room_id in published_room_ids,
events=recents,
prev_batch=prev_batch,
timeline=TimelineBatch(
events=recents,
prev_batch=prev_batch,
limited=False,
),
state=state,
limited=False,
ephemeral=typing_by_room.get(room_id, [])
)
if room_sync:
@ -344,11 +340,11 @@ class SyncHandler(BaseHandler):
limited = True
recents = []
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
room_key = now_token.room_key
end_key = room_key
timeline_limit = sync_config.filter.timeline_limit()
while limited and len(recents) < timeline_limit and max_repeat:
events, keys = yield self.store.get_recent_events_for_room(
@ -369,8 +365,9 @@ class SyncHandler(BaseHandler):
limited = False
max_repeat -= 1
if len(recents) > sync_config.limit:
recents = recents[-sync_config.limit:]
if len(recents) > timeline_limit:
limited = True
recents = recents[-timeline_limit:]
room_key = recents[0].internal_metadata.before
prev_batch_token = now_token.copy_and_replace(

View file

@ -158,7 +158,7 @@ class SyncRestServlet(RestServlet):
def encode_room(room, filter, time_now, token_id):
event_map = {}
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 = []
recent_event_ids = []
for event in state_events:
@ -178,13 +178,13 @@ class SyncRestServlet(RestServlet):
recent_event_ids.append(event.event_id)
result = {
"event_map": event_map,
"events": {
"batch": recent_event_ids,
"prev_batch": room.prev_batch.to_string(),
"timeline": {
"events": recent_event_ids,
"prev_batch": room.timeline.prev_batch.to_string(),
"limited": room.timeline.limited,
},
"state": state_event_ids,
"limited": room.limited,
"ephemeral": room.ephemeral,
"state": {"events": state_event_ids},
"ephemeral": {"events": room.ephemeral},
}
return result