guild.channels: subscribe users to the newly created channel

This commit is contained in:
Luna Mendes 2018-10-27 02:17:29 -03:00
parent 43b0482581
commit 0e3db251b8
2 changed files with 13 additions and 0 deletions

View File

@ -91,6 +91,17 @@ async def create_channel(guild_id):
await create_guild_channel( await create_guild_channel(
guild_id, new_channel_id, channel_type, **j) guild_id, new_channel_id, channel_type, **j)
# TODO: do a better method
# subscribe the currently subscribed users to the new channel
# by getting all user ids and subscribing each one by one.
# since GuildDispatcher calls Storage.get_channel_ids,
# it will subscribe all users to the newly created channel.
guild_pubsub = app.dispatcher.backends['guild']
user_ids = guild_pubsub.state[guild_id]
for uid in user_ids:
await app.dispatcher.sub('guild', guild_id, uid)
chan = await app.storage.get_channel(new_channel_id) chan = await app.storage.get_channel(new_channel_id)
await app.dispatcher.dispatch_guild( await app.dispatcher.dispatch_guild(
guild_id, 'CHANNEL_CREATE', chan) guild_id, 'CHANNEL_CREATE', chan)

View File

@ -46,6 +46,8 @@ class GuildDispatcher(DispatcherWithState):
# when subbing a user to the guild, we should sub them # when subbing a user to the guild, we should sub them
# to every channel they have access to, in the guild. # to every channel they have access to, in the guild.
# TODO: check for permissions
await self._chan_action('sub', guild_id, user_id) await self._chan_action('sub', guild_id, user_id)
async def unsub(self, guild_id: int, user_id: int): async def unsub(self, guild_id: int, user_id: int):