Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix invite state to always include all events #2163

Merged
merged 3 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -251,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to explain why this is necessary?


if as_client_event:
d = event_format(d)

Expand Down
9 changes: 3 additions & 6 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,9 @@ def is_inviter_member_event(e):

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)
Expand All @@ -545,7 +545,7 @@ def is_inviter_member_event(e):
"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)
Expand Down Expand Up @@ -618,6 +618,3 @@ def _notify():
)

preserve_fn(_notify)()

# If invite, remove room_state from unsigned before sending.
event.unsigned.pop("invite_room_state", None)
2 changes: 2 additions & 0 deletions synapse/rest/client/v2_alpha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ def encode_invited(self, rooms, time_now, token_id):
"""
invited = {}
for room in rooms:
logger.info("invite: %r", room.invite)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logging useful and how noisy is it?

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
Expand Down