mirror of https://gitlab.com/litecord/litecord.git
pubsub: add indirection layer to access flags
This commit is contained in:
parent
29d13c53b8
commit
49ed61438c
|
|
@ -84,6 +84,11 @@ class ChannelDispatcher(DispatcherWithFlags):
|
|||
await self.unsub(channel_id, user_id)
|
||||
continue
|
||||
|
||||
# skip typing events for users that don't want it
|
||||
if event.startswith('TYPING_') and \
|
||||
not self.flags_get(channel_id, user_id, 'typing', True):
|
||||
continue
|
||||
|
||||
cur_sess = []
|
||||
|
||||
if event in ('CHANNEL_CREATE', 'CHANNEL_UPDATE') \
|
||||
|
|
|
|||
|
|
@ -150,3 +150,10 @@ class DispatcherWithFlags(DispatcherWithState):
|
|||
"""Unsubscribe a user from the guild."""
|
||||
await super().unsub(key, identifier)
|
||||
self.flags[key].pop(identifier)
|
||||
|
||||
def flags_get(self, key, identifier, field: str, default):
|
||||
"""Get a single field from the flags store."""
|
||||
# yes, i know its simply an indirection from the main flags store,
|
||||
# but i'd rather have this than change every call if i ever change
|
||||
# the structure of the flags store.
|
||||
return self.flags[key][identifier].get(field, default)
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ class GuildDispatcher(DispatcherWithFlags):
|
|||
|
||||
# note that this does not equate to any unsubscription
|
||||
# of the channel.
|
||||
flags = self.flags[guild_id][user_id]
|
||||
if event.startswith('PRESENCE_') and not flags.get('presence', True):
|
||||
if event.startswith('PRESENCE_') and \
|
||||
not self.flags_get(guild_id, user_id, 'presence', True):
|
||||
continue
|
||||
|
||||
# filter the ones that matter
|
||||
|
|
|
|||
Loading…
Reference in New Issue