From 34e682d3855562a4ca6e32f366a2ecfa1c684a3a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 26 Apr 2017 16:18:08 +0100 Subject: [PATCH 1/3] Fix invite state to always include all events --- synapse/events/utils.py | 20 +++++++++++++++++++- synapse/handlers/message.py | 9 +++------ synapse/rest/client/v2_alpha/sync.py | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/synapse/events/utils.py b/synapse/events/utils.py index 5bbaef818..7ca779655 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -225,7 +225,22 @@ def format_event_for_client_v2_without_room_id(d): def serialize_event(e, time_now_ms, as_client_event=True, event_format=format_event_for_client_v1, - token_id=None, only_event_fields=None): + token_id=None, only_event_fields=None, is_invite=False): + """Serialize event for clients + + Args: + e (EventBase) + time_now_ms (int) + as_client_event (bool) + event_format + token_id + only_event_fields + is_invite (bool): Whether this is an invite that is being sent to the + invitee + + Returns: + dict + """ # FIXME(erikj): To handle the case of presence events and the like if not isinstance(e, EventBase): return e @@ -260,4 +275,7 @@ def serialize_event(e, time_now_ms, as_client_event=True, raise TypeError("only_event_fields must be a list of strings") d = only_fields(d, only_event_fields) + if not is_invite: + d["unsigned"].pop("invite_room_state", None) + return d diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 348056add..82a2ade1f 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -531,9 +531,9 @@ class MessageHandler(BaseHandler): state_to_include_ids = [ e_id - for k, e_id in context.current_state_ids.items() + for k, e_id in context.current_state_ids.iteritems() if k[0] in self.hs.config.room_invite_state_types - or k[0] == EventTypes.Member and k[1] == event.sender + or k == (EventTypes.Member, event.sender) ] state_to_include = yield self.store.get_events(state_to_include_ids) @@ -545,7 +545,7 @@ class MessageHandler(BaseHandler): "content": e.content, "sender": e.sender, } - for e in state_to_include.values() + for e in state_to_include.itervalues() ] invitee = UserID.from_string(event.state_key) @@ -618,6 +618,3 @@ class MessageHandler(BaseHandler): ) preserve_fn(_notify)() - - # If invite, remove room_state from unsigned before sending. - event.unsigned.pop("invite_room_state", None) diff --git a/synapse/rest/client/v2_alpha/sync.py b/synapse/rest/client/v2_alpha/sync.py index a7a9e0a79..b5bcfade7 100644 --- a/synapse/rest/client/v2_alpha/sync.py +++ b/synapse/rest/client/v2_alpha/sync.py @@ -250,9 +250,11 @@ class SyncRestServlet(RestServlet): """ invited = {} for room in rooms: + logger.info("invite: %r", room.invite) invite = serialize_event( room.invite, time_now, token_id=token_id, event_format=format_event_for_client_v2_without_room_id, + is_invite=True, ) unsigned = dict(invite.get("unsigned", {})) invite["unsigned"] = unsigned From 1e166470abf9a765eb66f5ea02382143f031e1fe Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 26 Apr 2017 16:23:30 +0100 Subject: [PATCH 2/3] Fix tests --- synapse/events/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/events/utils.py b/synapse/events/utils.py index 7ca779655..c42b73d11 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -266,6 +266,9 @@ def serialize_event(e, time_now_ms, as_client_event=True, if txn_id is not None: d["unsigned"]["transaction_id"] = txn_id + if not is_invite: + d["unsigned"].pop("invite_room_state", None) + if as_client_event: d = event_format(d) @@ -275,7 +278,4 @@ def serialize_event(e, time_now_ms, as_client_event=True, raise TypeError("only_event_fields must be a list of strings") d = only_fields(d, only_event_fields) - if not is_invite: - d["unsigned"].pop("invite_room_state", None) - return d From 46826bb078ac72ac8aea0d76c9e1c1f2ad29df97 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 27 Apr 2017 17:25:44 +0100 Subject: [PATCH 3/3] Comment and remove spurious logging --- synapse/events/utils.py | 3 +++ synapse/rest/client/v2_alpha/sync.py | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/synapse/events/utils.py b/synapse/events/utils.py index c42b73d11..824f4a42e 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -266,6 +266,9 @@ def serialize_event(e, time_now_ms, as_client_event=True, if txn_id is not None: d["unsigned"]["transaction_id"] = txn_id + # If this is an invite for somebody else, then we don't care about the + # invite_room_state as that's meant solely for the invitee. Other clients + # will already have the state since they're in the room. if not is_invite: d["unsigned"].pop("invite_room_state", None) diff --git a/synapse/rest/client/v2_alpha/sync.py b/synapse/rest/client/v2_alpha/sync.py index b5bcfade7..f30eab76f 100644 --- a/synapse/rest/client/v2_alpha/sync.py +++ b/synapse/rest/client/v2_alpha/sync.py @@ -250,7 +250,6 @@ class SyncRestServlet(RestServlet): """ invited = {} for room in rooms: - logger.info("invite: %r", room.invite) invite = serialize_event( room.invite, time_now, token_id=token_id, event_format=format_event_for_client_v2_without_room_id,