mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Some cleanup
This commit is contained in:
parent
1f403325ac
commit
d1fb790818
@ -253,12 +253,18 @@ class MessageHandler(BaseHandler):
|
|||||||
presence.bump_presence_active_time(user)
|
presence.bump_presence_active_time(user)
|
||||||
|
|
||||||
def deduplicate_state_event(self, event, context):
|
def deduplicate_state_event(self, event, context):
|
||||||
prev_state = context.current_state.get((event.type, event.state_key))
|
"""
|
||||||
if prev_state and event.user_id == prev_state.user_id:
|
Checks whether event is in the latest resolved state in context.
|
||||||
prev_content = encode_canonical_json(prev_state.content)
|
|
||||||
|
If so, returns the version of the event in context.
|
||||||
|
Otherwise, returns None.
|
||||||
|
"""
|
||||||
|
prev_event = context.current_state.get((event.type, event.state_key))
|
||||||
|
if prev_event and event.user_id == prev_event.user_id:
|
||||||
|
prev_content = encode_canonical_json(prev_event.content)
|
||||||
next_content = encode_canonical_json(event.content)
|
next_content = encode_canonical_json(event.content)
|
||||||
if prev_content == next_content:
|
if prev_content == next_content:
|
||||||
return prev_state
|
return prev_event
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -493,35 +493,24 @@ class RoomMemberHandler(BaseHandler):
|
|||||||
if prev_state is not None:
|
if prev_state is not None:
|
||||||
return
|
return
|
||||||
|
|
||||||
target_user_id = event.state_key
|
|
||||||
target_user = UserID.from_string(event.state_key)
|
target_user = UserID.from_string(event.state_key)
|
||||||
|
|
||||||
prev_state = context.current_state.get(
|
prev_state = context.current_state.get(
|
||||||
(EventTypes.Member, target_user_id),
|
(EventTypes.Member, target_user.to_string()),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
room_id = event.room_id
|
room_id = event.room_id
|
||||||
|
|
||||||
|
if event.membership == Membership.JOIN:
|
||||||
|
if is_guest and not self._can_guest_join(context.current_state):
|
||||||
|
# This should be an auth check, but guests are a local concept,
|
||||||
|
# so don't really fit into the general auth process.
|
||||||
|
raise AuthError(403, "Guest access not allowed")
|
||||||
|
|
||||||
# If we're trying to join a room then we have to do this differently
|
# If we're trying to join a room then we have to do this differently
|
||||||
# if this HS is not currently in the room, i.e. we have to do the
|
# if this HS is not currently in the room, i.e. we have to do the
|
||||||
# invite/join dance.
|
# invite/join dance.
|
||||||
if event.membership == Membership.JOIN:
|
|
||||||
if is_guest:
|
|
||||||
guest_access = context.current_state.get(
|
|
||||||
(EventTypes.GuestAccess, ""),
|
|
||||||
None
|
|
||||||
)
|
|
||||||
is_guest_access_allowed = (
|
|
||||||
guest_access
|
|
||||||
and guest_access.content
|
|
||||||
and "guest_access" in guest_access.content
|
|
||||||
and guest_access.content["guest_access"] == "can_join"
|
|
||||||
)
|
|
||||||
if not is_guest_access_allowed:
|
|
||||||
raise AuthError(403, "Guest access not allowed")
|
|
||||||
|
|
||||||
room_id = event.room_id
|
|
||||||
|
|
||||||
# XXX: We don't do an auth check if we are doing an invite
|
# XXX: We don't do an auth check if we are doing an invite
|
||||||
# join dance for now, since we're kinda implicitly checking
|
# join dance for now, since we're kinda implicitly checking
|
||||||
@ -599,6 +588,18 @@ class RoomMemberHandler(BaseHandler):
|
|||||||
user = UserID.from_string(event.user_id)
|
user = UserID.from_string(event.user_id)
|
||||||
user_left_room(self.distributor, user, event.room_id)
|
user_left_room(self.distributor, user, event.room_id)
|
||||||
|
|
||||||
|
def _can_guest_join(self, current_state):
|
||||||
|
"""
|
||||||
|
Returns whether a guest can join a room based on its current state.
|
||||||
|
"""
|
||||||
|
guest_access = current_state.get((EventTypes.GuestAccess, ""), None)
|
||||||
|
return (
|
||||||
|
guest_access
|
||||||
|
and guest_access.content
|
||||||
|
and "guest_access" in guest_access.content
|
||||||
|
and guest_access.content["guest_access"] == "can_join"
|
||||||
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def lookup_room_alias(self, room_alias):
|
def lookup_room_alias(self, room_alias):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user