Flatten the /sync response to remove the event_map

This commit is contained in:
Richard van der Hoff 2015-11-12 10:33:19 +00:00
parent f0ee1d515b
commit 3c3fc6b268
2 changed files with 14 additions and 24 deletions

View File

@ -129,10 +129,9 @@ def format_event_for_client_v2(d):
return d return d
def format_event_for_client_v2_without_event_id(d): def format_event_for_client_v2_without_room_id(d):
d = format_event_for_client_v2(d) d = format_event_for_client_v2(d)
d.pop("room_id", None) d.pop("room_id", None)
d.pop("event_id", None)
return d return d

View File

@ -22,7 +22,7 @@ from synapse.handlers.sync import SyncConfig
from synapse.types import StreamToken from synapse.types import StreamToken
from synapse.events import FrozenEvent from synapse.events import FrozenEvent
from synapse.events.utils import ( from synapse.events.utils import (
serialize_event, format_event_for_client_v2_without_event_id, serialize_event, format_event_for_client_v2_without_room_id,
) )
from synapse.api.filtering import FilterCollection from synapse.api.filtering import FilterCollection
from ._base import client_v2_pattern from ._base import client_v2_pattern
@ -207,7 +207,7 @@ class SyncRestServlet(RestServlet):
for room in rooms: for room in rooms:
invite = serialize_event( invite = serialize_event(
room.invite, time_now, token_id=token_id, room.invite, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_event_id, event_format=format_event_for_client_v2_without_room_id,
) )
invited_state = invite.get("unsigned", {}).pop("invite_room_state", []) invited_state = invite.get("unsigned", {}).pop("invite_room_state", [])
invited_state.append(invite) invited_state.append(invite)
@ -256,7 +256,13 @@ class SyncRestServlet(RestServlet):
:return: the room, encoded in our response format :return: the room, encoded in our response format
:rtype: dict[str, object] :rtype: dict[str, object]
""" """
event_map = {} def serialize(event):
# TODO(mjark): Respect formatting requirements in the filter.
return serialize_event(
event, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_room_id,
)
state_dict = room.state state_dict = room.state
timeline_events = filter.filter_room_timeline(room.timeline.events) timeline_events = filter.filter_room_timeline(room.timeline.events)
@ -264,36 +270,21 @@ class SyncRestServlet(RestServlet):
state_dict, timeline_events) state_dict, timeline_events)
state_events = filter.filter_room_state(state_dict.values()) state_events = filter.filter_room_state(state_dict.values())
state_event_ids = []
for event in state_events:
# TODO(mjark): Respect formatting requirements in the filter.
event_map[event.event_id] = serialize_event(
event, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_event_id,
)
state_event_ids.append(event.event_id)
timeline_event_ids = [] serialized_state = [serialize(e) for e in state_events]
for event in timeline_events: serialized_timeline = [serialize(e) for e in timeline_events]
# TODO(mjark): Respect formatting requirements in the filter.
event_map[event.event_id] = serialize_event(
event, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_event_id,
)
timeline_event_ids.append(event.event_id)
private_user_data = filter.filter_room_private_user_data( private_user_data = filter.filter_room_private_user_data(
room.private_user_data room.private_user_data
) )
result = { result = {
"event_map": event_map,
"timeline": { "timeline": {
"events": timeline_event_ids, "events": serialized_timeline,
"prev_batch": room.timeline.prev_batch.to_string(), "prev_batch": room.timeline.prev_batch.to_string(),
"limited": room.timeline.limited, "limited": room.timeline.limited,
}, },
"state": {"events": state_event_ids}, "state": serialized_state,
"private_user_data": {"events": private_user_data}, "private_user_data": {"events": private_user_data},
} }