0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 19:43:50 +01:00

Glue only_event_fields into the sync rest servlet

This commit is contained in:
Kegan Dougal 2016-11-22 10:14:05 +00:00
parent 0a8b0eeca1
commit cea4e4e7b2
3 changed files with 15 additions and 11 deletions

View file

@ -167,6 +167,7 @@ class FilterCollection(object):
self.include_leave = filter_json.get("room", {}).get( self.include_leave = filter_json.get("room", {}).get(
"include_leave", False "include_leave", False
) )
self.event_fields = filter_json.get("event_fields", [])
def __repr__(self): def __repr__(self):
return "<FilterCollection %s>" % (json.dumps(self._filter_json),) return "<FilterCollection %s>" % (json.dumps(self._filter_json),)

View file

@ -258,7 +258,7 @@ def serialize_event(e, time_now_ms, as_client_event=True,
if as_client_event: if as_client_event:
d = event_format(d) d = event_format(d)
if (isinstance(only_event_fields, list) and if (only_event_fields and isinstance(only_event_fields, list) and
all(isinstance(f, basestring) for f in only_event_fields)): all(isinstance(f, basestring) for f in only_event_fields)):
d = only_fields(d, only_event_fields) d = only_fields(d, only_event_fields)

View file

@ -162,7 +162,7 @@ class SyncRestServlet(RestServlet):
time_now = self.clock.time_msec() time_now = self.clock.time_msec()
joined = self.encode_joined( joined = self.encode_joined(
sync_result.joined, time_now, requester.access_token_id sync_result.joined, time_now, requester.access_token_id, filter.event_fields
) )
invited = self.encode_invited( invited = self.encode_invited(
@ -170,7 +170,7 @@ class SyncRestServlet(RestServlet):
) )
archived = self.encode_archived( archived = self.encode_archived(
sync_result.archived, time_now, requester.access_token_id sync_result.archived, time_now, requester.access_token_id, filter.event_fields
) )
response_content = { response_content = {
@ -197,7 +197,7 @@ class SyncRestServlet(RestServlet):
formatted.append(event) formatted.append(event)
return {"events": formatted} return {"events": formatted}
def encode_joined(self, rooms, time_now, token_id): def encode_joined(self, rooms, time_now, token_id, event_fields):
""" """
Encode the joined rooms in a sync result Encode the joined rooms in a sync result
@ -208,7 +208,8 @@ class SyncRestServlet(RestServlet):
calculations calculations
token_id(int): ID of the user's auth token - used for namespacing token_id(int): ID of the user's auth token - used for namespacing
of transaction IDs of transaction IDs
event_fields(list<str>): List of event fields to include. If empty,
all fields will be returned.
Returns: Returns:
dict[str, dict[str, object]]: the joined rooms list, in our dict[str, dict[str, object]]: the joined rooms list, in our
response format response format
@ -216,7 +217,7 @@ class SyncRestServlet(RestServlet):
joined = {} joined = {}
for room in rooms: for room in rooms:
joined[room.room_id] = self.encode_room( joined[room.room_id] = self.encode_room(
room, time_now, token_id room, time_now, token_id, only_fields=event_fields
) )
return joined return joined
@ -253,7 +254,7 @@ class SyncRestServlet(RestServlet):
return invited return invited
def encode_archived(self, rooms, time_now, token_id): def encode_archived(self, rooms, time_now, token_id, event_fields):
""" """
Encode the archived rooms in a sync result Encode the archived rooms in a sync result
@ -264,7 +265,8 @@ class SyncRestServlet(RestServlet):
calculations calculations
token_id(int): ID of the user's auth token - used for namespacing token_id(int): ID of the user's auth token - used for namespacing
of transaction IDs of transaction IDs
event_fields(list<str>): List of event fields to include. If empty,
all fields will be returned.
Returns: Returns:
dict[str, dict[str, object]]: The invited rooms list, in our dict[str, dict[str, object]]: The invited rooms list, in our
response format response format
@ -272,13 +274,13 @@ class SyncRestServlet(RestServlet):
joined = {} joined = {}
for room in rooms: for room in rooms:
joined[room.room_id] = self.encode_room( joined[room.room_id] = self.encode_room(
room, time_now, token_id, joined=False room, time_now, token_id, joined=False, only_fields=event_fields
) )
return joined return joined
@staticmethod @staticmethod
def encode_room(room, time_now, token_id, joined=True): def encode_room(room, time_now, token_id, joined=True, only_fields=None):
""" """
Args: Args:
room (JoinedSyncResult|ArchivedSyncResult): sync result for a room (JoinedSyncResult|ArchivedSyncResult): sync result for a
@ -289,7 +291,7 @@ class SyncRestServlet(RestServlet):
of transaction IDs of transaction IDs
joined (bool): True if the user is joined to this room - will mean joined (bool): True if the user is joined to this room - will mean
we handle ephemeral events we handle ephemeral events
only_fields(list<str>): Optional. The list of event fields to include.
Returns: Returns:
dict[str, object]: the room, encoded in our response format dict[str, object]: the room, encoded in our response format
""" """
@ -298,6 +300,7 @@ class SyncRestServlet(RestServlet):
return serialize_event( return serialize_event(
event, time_now, token_id=token_id, event, time_now, token_id=token_id,
event_format=format_event_for_client_v2_without_room_id, event_format=format_event_for_client_v2_without_room_id,
only_event_fields=only_fields,
) )
state_dict = room.state state_dict = room.state