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

Commit

Permalink
Let users see their own leave events
Browse files Browse the repository at this point in the history
... otherwise clients get confused.

Fixes https://matrix.org/jira/browse/SYN-662,
element-hq/element-web#368
  • Loading branch information
richvdh committed Apr 6, 2016
1 parent b713934 commit 1e05637
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions synapse/handlers/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
)


MEMBERSHIP_PRIORITY = (
Membership.JOIN,
Membership.INVITE,
Membership.KNOCK,
Membership.LEAVE,
Membership.BAN,
)


class BaseHandler(object):
"""
Common base class for the event handlers.
Expand Down Expand Up @@ -72,6 +81,7 @@ def filter_events_for_clients(self, user_tuples, events, event_id_to_state):
* the user is not currently a member of the room, and:
* the user has not been a member of the room since the
given events
events ([synapse.events.EventBase]): list of events to filter
"""
forgotten = yield defer.gatherResults([
self.store.who_forgot_in_room(
Expand All @@ -86,6 +96,12 @@ def filter_events_for_clients(self, user_tuples, events, event_id_to_state):
)

def allowed(event, user_id, is_peeking):
"""
Args:
event (synapse.events.EventBase): event to check
user_id (str)
is_peeking (bool)
"""
state = event_id_to_state[event.event_id]

# get the room_visibility at the time of the event.
Expand Down Expand Up @@ -117,17 +133,30 @@ def allowed(event, user_id, is_peeking):
if old_priority < new_priority:
visibility = prev_visibility

# get the user's membership at the time of the event. (or rather,
# just *after* the event. Which means that people can see their
# own join events, but not (currently) their own leave events.)
membership_event = state.get((EventTypes.Member, user_id), None)
if membership_event:
if membership_event.event_id in event_id_forgotten:
membership = None
else:
membership = membership_event.membership
else:
membership = None
# likewise, if the event is the user's own membership event, use
# the 'most joined' membership
membership = None
if event.type == EventTypes.Member and event.state_key == user_id:
membership = event.content.get("membership", None)
if membership not in MEMBERSHIP_PRIORITY:
membership = "leave"

prev_content = event.unsigned.get("prev_content", {})
prev_membership = prev_content.get("membership", None)
if prev_membership not in MEMBERSHIP_PRIORITY:
prev_membership = "leave"

new_priority = MEMBERSHIP_PRIORITY.index(membership)
old_priority = MEMBERSHIP_PRIORITY.index(prev_membership)
if old_priority < new_priority:
membership = prev_membership

# otherwise, get the user's membership at the time of the event.
if membership is None:
membership_event = state.get((EventTypes.Member, user_id), None)
if membership_event:
if membership_event.event_id not in event_id_forgotten:
membership = membership_event.membership

# if the user was a member of the room at the time of the event,
# they can see it.
Expand Down

0 comments on commit 1e05637

Please sign in to comment.