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 #5220 from matrix-org/erikj/dont_bundle_live_events
Browse files Browse the repository at this point in the history
Don't bundle aggregations with events in /sync or /events or state queries
  • Loading branch information
erikjohnston authored May 24, 2019
2 parents 8c41c04 + 4cb577c commit d16f557
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/5220.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental support for relations (aka reactions and edits).
5 changes: 3 additions & 2 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,13 @@ def __init__(self, hs):
)

@defer.inlineCallbacks
def serialize_event(self, event, time_now, **kwargs):
def serialize_event(self, event, time_now, bundle_aggregations=True, **kwargs):
"""Serializes a single event.
Args:
event (EventBase)
time_now (int): The current time in milliseconds
bundle_aggregations (bool): Whether to bundle in related events
**kwargs: Arguments to pass to `serialize_event`
Returns:
Expand All @@ -350,7 +351,7 @@ def serialize_event(self, event, time_now, **kwargs):

# If MSC1849 is enabled then we need to look if thre are any relations
# we need to bundle in with the event
if self.experimental_msc1849_support_enabled:
if self.experimental_msc1849_support_enabled and bundle_aggregations:
annotations = yield self.store.get_aggregation_groups_for_event(
event_id,
)
Expand Down
3 changes: 3 additions & 0 deletions synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def get_stream(self, auth_user_id, pagin_config, timeout=0,

chunks = yield self._event_serializer.serialize_events(
events, time_now, as_client_event=as_client_event,
# We don't bundle "live" events, as otherwise clients
# will end up double counting annotations.
bundle_aggregations=False,
)

chunk = {
Expand Down
3 changes: 3 additions & 0 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ def get_state_events(
now = self.clock.time_msec()
events = yield self._event_serializer.serialize_events(
room_state.values(), now,
# We don't bother bundling aggregations in when asked for state
# events, as clients won't use them.
bundle_aggregations=False,
)
defer.returnValue(events)

Expand Down
3 changes: 3 additions & 0 deletions synapse/rest/client/v2_alpha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ def encode_room(
def serialize(events):
return self._event_serializer.serialize_events(
events, time_now=time_now,
# We don't bundle "live" events, as otherwise clients
# will end up double counting annotations.
bundle_aggregations=False,
token_id=token_id,
event_format=event_formatter,
only_event_fields=only_fields,
Expand Down

0 comments on commit d16f557

Please sign in to comment.