Simplify boolean logic and avoid set construction

See https://github.com/element-hq/synapse/pull/17187#discussion_r1629853770
This commit is contained in:
Eric Eastwood 2024-06-06 12:03:17 -05:00
parent 0153a6e535
commit 6f10b9722d

View file

@ -53,14 +53,13 @@ def filter_membership_for_sync(*, membership: str, user_id: str, sender: str) ->
sender: The person who sent the membership event sender: The person who sent the membership event
""" """
return ( # Everything except `Membership.LEAVE` because we want everything that's *still*
# Everything except `Membership.LEAVE` because we want everything that's *still* # relevant to the user. There are few more things to include in the sync response
# relevant to the user. There are few more things to include in the sync response # (newly_left) but those are handled separately.
# (newly_left) but those are handled separately. #
membership in (Membership.LIST - {Membership.LEAVE}) # This logic includes kicks (leave events where the sender is not the same user) and
# Include kicks # can be read as "anything that isn't a leave or a leave with a different sender".
or (membership == Membership.LEAVE and sender != user_id) return membership != Membership.LEAVE or sender != user_id
)
class SlidingSyncConfig(SlidingSyncBody): class SlidingSyncConfig(SlidingSyncBody):