From da669e5fb2ec2ceee3df4017c195a4edb56e6e43 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 17 Feb 2019 00:10:14 -0300 Subject: [PATCH] dm_channels: add sub/unsub logic on add/remove of recipient - fix gdm remove call on remove_from_group_dm --- litecord/blueprints/dm_channels.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litecord/blueprints/dm_channels.py b/litecord/blueprints/dm_channels.py index 1a66494..1f0f4cc 100644 --- a/litecord/blueprints/dm_channels.py +++ b/litecord/blueprints/dm_channels.py @@ -87,6 +87,7 @@ async def _gdm_add_recipient(channel_id: int, peer_id: int, *, user_id=None): chan = await app.storage.get_channel(channel_id) await app.dispatcher.dispatch('user', peer_id, 'CHANNEL_CREATE', chan) await app.dispatcher.dispatch('channel', channel_id, 'CHANNEL_UPDATE', chan) + await app.dispatcher.sub('channel', peer_id) if user_id: await send_sys_message( @@ -115,6 +116,8 @@ async def _gdm_remove_recipient(channel_id: int, peer_id: int, *, user_id=None): } ) + await app.dispatcher.unsub('channel', peer_id) + if user_id: await send_sys_message( app, channel_id, MessageType.RECIPIENT_REMOVE, @@ -155,8 +158,8 @@ async def add_to_group_dm(dm_chan, peer_id): ) -@bp.route('//recipients/', methods=['DELETE']) -async def remove_from_group_dm(dm_chan, user_id): +@bp.route('//recipients/', methods=['DELETE']) +async def remove_from_group_dm(dm_chan, peer_id): """Remove users from group dm.""" user_id = await token_check() _ctype, owner_id = await channel_check( @@ -166,5 +169,5 @@ async def remove_from_group_dm(dm_chan, user_id): if owner_id != user_id: raise Forbidden('You are now the owner of the group DM') - await _gdm_remove_recipient(dm_chan, user_id) + await _gdm_remove_recipient(dm_chan, peer_id) return '', 204