Include transaction ids in unsigned section of events in the sync results for the clients that made those requests

This commit is contained in:
Mark Haines 2015-01-29 02:45:33 +00:00
parent 1b4a164c02
commit b9c442c85c
2 changed files with 22 additions and 12 deletions

View File

@ -103,7 +103,7 @@ def format_event_for_client_v1(d):
drop_keys = ( drop_keys = (
"auth_events", "prev_events", "hashes", "signatures", "depth", "auth_events", "prev_events", "hashes", "signatures", "depth",
"unsigned", "origin" "unsigned", "origin", "prev_state"
) )
for key in drop_keys: for key in drop_keys:
d.pop(key, None) d.pop(key, None)
@ -112,7 +112,8 @@ def format_event_for_client_v1(d):
def format_event_for_client_v2(d): def format_event_for_client_v2(d):
drop_keys = ( drop_keys = (
"auth_events", "prev_events", "hashes", "signatures", "depth", "origin" "auth_events", "prev_events", "hashes", "signatures", "depth",
"origin", "prev_state",
) )
for key in drop_keys: for key in drop_keys:
d.pop(key, None) d.pop(key, None)
@ -140,7 +141,7 @@ def serialize_event(e, time_now_ms, as_client_event=True,
if "age_ts" in d["unsigned"]: if "age_ts" in d["unsigned"]:
d["unsigned"]["age"] = time_now_ms - d["unsigned"]["age_ts"] d["unsigned"]["age"] = time_now_ms - d["unsigned"]["age_ts"]
d["unsigned"]["age_ts"] del d["unsigned"]["age_ts"]
if "redacted_because" in e.unsigned: if "redacted_because" in e.unsigned:
d["unsigned"]["redacted_because"] = serialize_event( d["unsigned"]["redacted_because"] = serialize_event(
@ -148,8 +149,8 @@ def serialize_event(e, time_now_ms, as_client_event=True,
) )
if token_id is not None: if token_id is not None:
if token_id == e.internal_metadata["token_id"]: if token_id == getattr(e.internal_metadata, "token_id", None):
txn_id = e.internal_metadata.get("txn_id", None) txn_id = getattr(e.internal_metadata, "txn_id", None)
if txn_id is not None: if txn_id is not None:
d["unsigned"]["transaction_id"] = txn_id d["unsigned"]["transaction_id"] = txn_id

View File

@ -18,7 +18,9 @@ from twisted.internet import defer
from synapse.http.servlet import RestServlet from synapse.http.servlet import RestServlet
from synapse.handlers.sync import SyncConfig from synapse.handlers.sync import SyncConfig
from synapse.types import StreamToken from synapse.types import StreamToken
from synapse.events.utils import serialize_event from synapse.events.utils import (
serialize_event, format_event_for_client_v2_without_event_id,
)
from ._base import client_v2_pattern from ._base import client_v2_pattern
import logging import logging
@ -139,7 +141,9 @@ class SyncRestServlet(RestServlet):
"private_user_data": self.encode_events( "private_user_data": self.encode_events(
sync_result.private_user_data, filter, time_now sync_result.private_user_data, filter, time_now
), ),
"rooms": self.encode_rooms(sync_result.rooms, filter, time_now), "rooms": self.encode_rooms(
sync_result.rooms, filter, time_now, client.token_id
),
"next_batch": sync_result.next_batch.to_string(), "next_batch": sync_result.next_batch.to_string(),
} }
@ -153,25 +157,30 @@ class SyncRestServlet(RestServlet):
# TODO(mjark): Respect formatting requirements in the filter. # TODO(mjark): Respect formatting requirements in the filter.
return serialize_event(event, time_now) return serialize_event(event, time_now)
def encode_rooms(self, rooms, filter, time_now): def encode_rooms(self, rooms, filter, time_now, token_id):
return [self.encode_room(room, filter, time_now) for room in rooms] return [
self.encode_room(room, filter, time_now, token_id)
for room in rooms
]
@staticmethod @staticmethod
def encode_room(room, filter, time_now): def encode_room(room, filter, time_now, token_id):
event_map = {} event_map = {}
state_event_ids = [] state_event_ids = []
recent_event_ids = [] recent_event_ids = []
for event in room.state: for event in room.state:
# TODO(mjark): Respect formatting requirements in the filter. # TODO(mjark): Respect formatting requirements in the filter.
event_map[event.event_id] = serialize_event( event_map[event.event_id] = serialize_event(
event, time_now, strip_ids=True event, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_event_id,
) )
state_event_ids.append(event.event_id) state_event_ids.append(event.event_id)
for event in room.events: for event in room.events:
# TODO(mjark): Respect formatting requirements in the filter. # TODO(mjark): Respect formatting requirements in the filter.
event_map[event.event_id] = serialize_event( event_map[event.event_id] = serialize_event(
event, time_now, strip_ids=True event, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_event_id,
) )
recent_event_ids.append(event.event_id) recent_event_ids.append(event.event_id)
return { return {