forked from MirrorHub/synapse
Let users see their own leave events
... otherwise clients get confused. Fixes https://matrix.org/jira/browse/SYN-662, https://github.com/vector-im/vector-web/issues/368
This commit is contained in:
parent
b713934b2e
commit
1e05637e37
1 changed files with 40 additions and 11 deletions
|
@ -37,6 +37,15 @@ VISIBILITY_PRIORITY = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
MEMBERSHIP_PRIORITY = (
|
||||||
|
Membership.JOIN,
|
||||||
|
Membership.INVITE,
|
||||||
|
Membership.KNOCK,
|
||||||
|
Membership.LEAVE,
|
||||||
|
Membership.BAN,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BaseHandler(object):
|
class BaseHandler(object):
|
||||||
"""
|
"""
|
||||||
Common base class for the event handlers.
|
Common base class for the event handlers.
|
||||||
|
@ -72,6 +81,7 @@ class BaseHandler(object):
|
||||||
* the user is not currently a member of the room, and:
|
* the user is not currently a member of the room, and:
|
||||||
* the user has not been a member of the room since the
|
* the user has not been a member of the room since the
|
||||||
given events
|
given events
|
||||||
|
events ([synapse.events.EventBase]): list of events to filter
|
||||||
"""
|
"""
|
||||||
forgotten = yield defer.gatherResults([
|
forgotten = yield defer.gatherResults([
|
||||||
self.store.who_forgot_in_room(
|
self.store.who_forgot_in_room(
|
||||||
|
@ -86,6 +96,12 @@ class BaseHandler(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def allowed(event, user_id, is_peeking):
|
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]
|
state = event_id_to_state[event.event_id]
|
||||||
|
|
||||||
# get the room_visibility at the time of the event.
|
# get the room_visibility at the time of the event.
|
||||||
|
@ -117,17 +133,30 @@ class BaseHandler(object):
|
||||||
if old_priority < new_priority:
|
if old_priority < new_priority:
|
||||||
visibility = prev_visibility
|
visibility = prev_visibility
|
||||||
|
|
||||||
# get the user's membership at the time of the event. (or rather,
|
# likewise, if the event is the user's own membership event, use
|
||||||
# just *after* the event. Which means that people can see their
|
# the 'most joined' membership
|
||||||
# own join events, but not (currently) their own leave events.)
|
membership = None
|
||||||
membership_event = state.get((EventTypes.Member, user_id), None)
|
if event.type == EventTypes.Member and event.state_key == user_id:
|
||||||
if membership_event:
|
membership = event.content.get("membership", None)
|
||||||
if membership_event.event_id in event_id_forgotten:
|
if membership not in MEMBERSHIP_PRIORITY:
|
||||||
membership = None
|
membership = "leave"
|
||||||
else:
|
|
||||||
membership = membership_event.membership
|
prev_content = event.unsigned.get("prev_content", {})
|
||||||
else:
|
prev_membership = prev_content.get("membership", None)
|
||||||
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,
|
# if the user was a member of the room at the time of the event,
|
||||||
# they can see it.
|
# they can see it.
|
||||||
|
|
Loading…
Reference in a new issue