Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #389 from matrix-org/rav/flatten_sync_response
Browse files Browse the repository at this point in the history
v2 sync: Get rid of the event_map, and rename the keys of the rooms obj
  • Loading branch information
richvdh committed Nov 20, 2015
2 parents 3f151da + dd11bf8 commit 1d9c1d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
3 changes: 1 addition & 2 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ def format_event_for_client_v2(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.pop("room_id", None)
d.pop("event_id", None)
return d


Expand Down
41 changes: 16 additions & 25 deletions synapse/rest/client/v2_alpha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from synapse.types import StreamToken
from synapse.events import FrozenEvent
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 ._base import client_v2_pattern
Expand Down Expand Up @@ -148,9 +148,9 @@ def on_GET(self, request):
sync_result.presence, filter, time_now
),
"rooms": {
"joined": joined,
"invited": invited,
"archived": archived,
"join": joined,
"invite": invited,
"leave": archived,
},
"next_batch": sync_result.next_batch.to_string(),
}
Expand Down Expand Up @@ -207,7 +207,7 @@ def encode_invited(self, rooms, filter, time_now, token_id):
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,
event_format=format_event_for_client_v2_without_room_id,
)
invited_state = invite.get("unsigned", {}).pop("invite_room_state", [])
invited_state.append(invite)
Expand Down Expand Up @@ -256,44 +256,35 @@ def encode_room(room, filter, time_now, token_id, joined=True):
:return: the room, encoded in our response format
: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
timeline_events = filter.filter_room_timeline(room.timeline.events)

state_dict = SyncRestServlet._rollback_state_for_timeline(
state_dict, timeline_events)

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 = []
for event 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)
serialized_state = [serialize(e) for e in state_events]
serialized_timeline = [serialize(e) for e in timeline_events]

account_data = filter.filter_room_account_data(
room.account_data
)

result = {
"event_map": event_map,
"timeline": {
"events": timeline_event_ids,
"events": serialized_timeline,
"prev_batch": room.timeline.prev_batch.to_string(),
"limited": room.timeline.limited,
},
"state": {"events": state_event_ids},
"state": {"events": serialized_state},
"account_data": {"events": account_data},
}

Expand Down

0 comments on commit 1d9c1d4

Please sign in to comment.