mirror of https://gitlab.com/litecord/litecord.git
fix new joins not subscribing to channels
This commit is contained in:
parent
9273d8cbda
commit
d1b10e7409
|
|
@ -329,7 +329,12 @@ async def add_member(guild_id: int, user_id: int, *, basic=False):
|
||||||
|
|
||||||
# pubsub changes for new member
|
# pubsub changes for new member
|
||||||
await app.lazy_guild.new_member(guild_id, user_id)
|
await app.lazy_guild.new_member(guild_id, user_id)
|
||||||
states = await app.dispatcher.guild.sub_user(guild_id, user_id)
|
|
||||||
|
# TODO how to remove repetition between this and websocket's subscribe_all?
|
||||||
|
states, channels = await app.dispatcher.guild.sub_user(guild_id, user_id)
|
||||||
|
for channel_id in channel_ids:
|
||||||
|
for state in states:
|
||||||
|
await app.dispatcher.channel.sub(channel_id, state.session_id)
|
||||||
|
|
||||||
guild = await app.storage.get_guild_full(guild_id, user_id, 250)
|
guild = await app.storage.get_guild_full(guild_id, user_id, 250)
|
||||||
for state in states:
|
for state in states:
|
||||||
|
|
|
||||||
|
|
@ -506,20 +506,8 @@ class GatewayWebsocket:
|
||||||
channel_ids: List[int] = []
|
channel_ids: List[int] = []
|
||||||
|
|
||||||
for guild_id in guild_ids:
|
for guild_id in guild_ids:
|
||||||
await app.dispatcher.guild.sub(guild_id, session_id)
|
_, channels = await app.dispatcher.guild.sub_user(guild_id, session_id)
|
||||||
|
channel_ids.extend(channels)
|
||||||
# instead of calculating which channels to subscribe to
|
|
||||||
# inside guild dispatcher, we calculate them in here, so that
|
|
||||||
# we remove complexity of the dispatcher.
|
|
||||||
|
|
||||||
guild_chan_ids = await app.storage.get_channel_ids(guild_id)
|
|
||||||
for channel_id in guild_chan_ids:
|
|
||||||
perms = await get_permissions(
|
|
||||||
self.state.user_id, channel_id, storage=self.storage
|
|
||||||
)
|
|
||||||
|
|
||||||
if perms.bits.read_messages:
|
|
||||||
channel_ids.append(channel_id)
|
|
||||||
|
|
||||||
log.info("subscribing to {} guild channels", len(channel_ids))
|
log.info("subscribing to {} guild channels", len(channel_ids))
|
||||||
for channel_id in channel_ids:
|
for channel_id in channel_ids:
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ from logbook import Logger
|
||||||
from .dispatcher import DispatcherWithState, GatewayEvent
|
from .dispatcher import DispatcherWithState, GatewayEvent
|
||||||
from litecord.gateway.state import GatewayState
|
from litecord.gateway.state import GatewayState
|
||||||
from litecord.enums import EVENTS_TO_INTENTS
|
from litecord.enums import EVENTS_TO_INTENTS
|
||||||
|
from litecord.permissions import get_permissions
|
||||||
|
|
||||||
|
|
||||||
log = Logger(__name__)
|
log = Logger(__name__)
|
||||||
|
|
||||||
|
|
@ -48,12 +50,28 @@ def can_dispatch(event_type, event_data, state) -> bool:
|
||||||
class GuildDispatcher(DispatcherWithState[int, str, GatewayEvent, List[str]]):
|
class GuildDispatcher(DispatcherWithState[int, str, GatewayEvent, List[str]]):
|
||||||
"""Guild backend for Pub/Sub."""
|
"""Guild backend for Pub/Sub."""
|
||||||
|
|
||||||
async def sub_user(self, guild_id: int, user_id: int) -> List[GatewayState]:
|
async def sub_user(
|
||||||
|
self, guild_id: int, user_id: int
|
||||||
|
) -> Tuple[List[GatewayState], List[int]]:
|
||||||
states = app.state_manager.fetch_states(user_id, guild_id)
|
states = app.state_manager.fetch_states(user_id, guild_id)
|
||||||
for state in states:
|
for state in states:
|
||||||
await self.sub(guild_id, state.session_id)
|
await self.sub(guild_id, state.session_id)
|
||||||
|
|
||||||
return states
|
# instead of calculating which channels to subscribe to
|
||||||
|
# inside guild dispatcher, we calculate them in here, so that
|
||||||
|
# we remove complexity of the dispatcher.
|
||||||
|
|
||||||
|
guild_chan_ids = await app.storage.get_channel_ids(guild_id)
|
||||||
|
channel_ids = []
|
||||||
|
for channel_id in guild_chan_ids:
|
||||||
|
perms = await get_permissions(
|
||||||
|
self.state.user_id, channel_id, storage=self.storage
|
||||||
|
)
|
||||||
|
|
||||||
|
if perms.bits.read_messages:
|
||||||
|
channel_ids.append(channel_id)
|
||||||
|
|
||||||
|
return states, channel_ids
|
||||||
|
|
||||||
async def dispatch_filter(
|
async def dispatch_filter(
|
||||||
self, guild_id: int, filter_function, event: GatewayEvent
|
self, guild_id: int, filter_function, event: GatewayEvent
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue