mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-09-08 05:01:58 +00:00
Return the raw federation event rather than adding extra keys for federation data.
This commit is contained in:
parent
5940ec993b
commit
edb557b2ad
@ -89,13 +89,21 @@ def prune_event(event):
|
|||||||
return type(event)(allowed_fields)
|
return type(event)(allowed_fields)
|
||||||
|
|
||||||
|
|
||||||
def serialize_event(hs, e, remove_data=True):
|
def serialize_event(hs, e, client_event=True):
|
||||||
# FIXME(erikj): To handle the case of presence events and the like
|
# FIXME(erikj): To handle the case of presence events and the like
|
||||||
if not isinstance(e, EventBase):
|
if not isinstance(e, EventBase):
|
||||||
return e
|
return e
|
||||||
|
|
||||||
# Should this strip out None's?
|
# Should this strip out None's?
|
||||||
d = {k: v for k, v in e.get_dict().items()}
|
d = {k: v for k, v in e.get_dict().items()}
|
||||||
|
|
||||||
|
if not client_event:
|
||||||
|
# set the age and keep all other keys
|
||||||
|
if "age_ts" in d["unsigned"]:
|
||||||
|
now = int(hs.get_clock().time_msec())
|
||||||
|
d["unsigned"]["age"] = now - d["unsigned"]["age_ts"]
|
||||||
|
return d
|
||||||
|
|
||||||
if "age_ts" in d["unsigned"]:
|
if "age_ts" in d["unsigned"]:
|
||||||
now = int(hs.get_clock().time_msec())
|
now = int(hs.get_clock().time_msec())
|
||||||
d["unsigned"]["age"] = now - d["unsigned"]["age_ts"]
|
d["unsigned"]["age"] = now - d["unsigned"]["age_ts"]
|
||||||
@ -122,7 +130,6 @@ def serialize_event(hs, e, remove_data=True):
|
|||||||
d["prev_content"] = e.unsigned["prev_content"]
|
d["prev_content"] = e.unsigned["prev_content"]
|
||||||
del d["unsigned"]["prev_content"]
|
del d["unsigned"]["prev_content"]
|
||||||
|
|
||||||
if remove_data:
|
|
||||||
del d["auth_events"]
|
del d["auth_events"]
|
||||||
del d["prev_events"]
|
del d["prev_events"]
|
||||||
del d["hashes"]
|
del d["hashes"]
|
||||||
|
@ -47,7 +47,7 @@ class EventStreamHandler(BaseHandler):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def get_stream(self, auth_user_id, pagin_config, timeout=0,
|
def get_stream(self, auth_user_id, pagin_config, timeout=0,
|
||||||
trim_events=True):
|
as_client_event=True):
|
||||||
auth_user = self.hs.parse_userid(auth_user_id)
|
auth_user = self.hs.parse_userid(auth_user_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -80,7 +80,7 @@ class EventStreamHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
|
|
||||||
chunks = [
|
chunks = [
|
||||||
self.hs.serialize_event(e, trim_events) for e in events
|
self.hs.serialize_event(e, as_client_event) for e in events
|
||||||
]
|
]
|
||||||
|
|
||||||
chunk = {
|
chunk = {
|
||||||
|
@ -211,7 +211,7 @@ class MessageHandler(BaseHandler):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def snapshot_all_rooms(self, user_id=None, pagin_config=None,
|
def snapshot_all_rooms(self, user_id=None, pagin_config=None,
|
||||||
feedback=False, trim_events=True):
|
feedback=False, as_client_event=True):
|
||||||
"""Retrieve a snapshot of all rooms the user is invited or has joined.
|
"""Retrieve a snapshot of all rooms the user is invited or has joined.
|
||||||
|
|
||||||
This snapshot may include messages for all rooms where the user is
|
This snapshot may include messages for all rooms where the user is
|
||||||
@ -222,6 +222,7 @@ class MessageHandler(BaseHandler):
|
|||||||
pagin_config (synapse.api.streams.PaginationConfig): The pagination
|
pagin_config (synapse.api.streams.PaginationConfig): The pagination
|
||||||
config used to determine how many messages *PER ROOM* to return.
|
config used to determine how many messages *PER ROOM* to return.
|
||||||
feedback (bool): True to get feedback along with these messages.
|
feedback (bool): True to get feedback along with these messages.
|
||||||
|
as_client_event (bool): True to get events in client-server format.
|
||||||
Returns:
|
Returns:
|
||||||
A list of dicts with "room_id" and "membership" keys for all rooms
|
A list of dicts with "room_id" and "membership" keys for all rooms
|
||||||
the user is currently invited or joined in on. Rooms where the user
|
the user is currently invited or joined in on. Rooms where the user
|
||||||
@ -281,7 +282,7 @@ class MessageHandler(BaseHandler):
|
|||||||
|
|
||||||
d["messages"] = {
|
d["messages"] = {
|
||||||
"chunk": [
|
"chunk": [
|
||||||
self.hs.serialize_event(m, trim_events)
|
self.hs.serialize_event(m, as_client_event)
|
||||||
for m in messages
|
for m in messages
|
||||||
],
|
],
|
||||||
"start": start_token.to_string(),
|
"start": start_token.to_string(),
|
||||||
|
@ -44,11 +44,11 @@ class EventStreamRestServlet(RestServlet):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise SynapseError(400, "timeout must be in milliseconds.")
|
raise SynapseError(400, "timeout must be in milliseconds.")
|
||||||
|
|
||||||
trim_events = "raw" not in request.args
|
as_client_event = "raw" not in request.args
|
||||||
|
|
||||||
chunk = yield handler.get_stream(
|
chunk = yield handler.get_stream(
|
||||||
auth_user.to_string(), pagin_config, timeout=timeout,
|
auth_user.to_string(), pagin_config, timeout=timeout,
|
||||||
trim_events=trim_events
|
as_client_event=as_client_event
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
logger.exception("Event stream failed")
|
logger.exception("Event stream failed")
|
||||||
|
@ -27,14 +27,14 @@ class InitialSyncRestServlet(RestServlet):
|
|||||||
def on_GET(self, request):
|
def on_GET(self, request):
|
||||||
user = yield self.auth.get_user_by_req(request)
|
user = yield self.auth.get_user_by_req(request)
|
||||||
with_feedback = "feedback" in request.args
|
with_feedback = "feedback" in request.args
|
||||||
trim_events = "raw" not in request.args
|
as_client_event = "raw" not in request.args
|
||||||
pagination_config = PaginationConfig.from_request(request)
|
pagination_config = PaginationConfig.from_request(request)
|
||||||
handler = self.handlers.message_handler
|
handler = self.handlers.message_handler
|
||||||
content = yield handler.snapshot_all_rooms(
|
content = yield handler.snapshot_all_rooms(
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
pagin_config=pagination_config,
|
pagin_config=pagination_config,
|
||||||
feedback=with_feedback,
|
feedback=with_feedback,
|
||||||
trim_events=trim_events
|
as_client_event=as_client_event
|
||||||
)
|
)
|
||||||
|
|
||||||
defer.returnValue((200, content))
|
defer.returnValue((200, content))
|
||||||
|
@ -149,8 +149,8 @@ class BaseHomeServer(object):
|
|||||||
object."""
|
object."""
|
||||||
return EventID.from_string(s)
|
return EventID.from_string(s)
|
||||||
|
|
||||||
def serialize_event(self, e, remove_data=True):
|
def serialize_event(self, e, as_client_event=True):
|
||||||
return serialize_event(self, e, remove_data)
|
return serialize_event(self, e, as_client_event)
|
||||||
|
|
||||||
def get_ip_from_request(self, request):
|
def get_ip_from_request(self, request):
|
||||||
# May be an X-Forwarding-For header depending on config
|
# May be an X-Forwarding-For header depending on config
|
||||||
|
Loading…
Reference in New Issue
Block a user