diff --git a/litecord/blueprints/channels.py b/litecord/blueprints/channels.py index 3faa800..e151391 100644 --- a/litecord/blueprints/channels.py +++ b/litecord/blueprints/channels.py @@ -195,12 +195,16 @@ async def close_channel(channel_id): # the request via removing the link between them and # the channel on dm_channel_state await app.db.execute(""" - DELETE FROM dm_channel_state (user_id, dm_id) - VALUES ($1, $2) + DELETE FROM dm_channel_state + WHERE user_id = $1 AND dm_id = $2 """, user_id, channel_id) + # unsubscribe + await app.dispatcher.unsub('channel', channel_id, user_id) + # nothing happens to the other party of the dm channel - await app.dispacher.dispatch_user(user_id, 'CHANNEL_DELETE', chan) + await app.dispatcher.dispatch_user(user_id, 'CHANNEL_DELETE', chan) + return jsonify(chan) if ctype == ChannelType.GROUP_DM: diff --git a/litecord/dispatcher.py b/litecord/dispatcher.py index 1067df6..f821f01 100644 --- a/litecord/dispatcher.py +++ b/litecord/dispatcher.py @@ -46,6 +46,12 @@ class EventDispatcher: backend, key, identifier, backend) return await self.action(backend, 'unsub', key, identifier) + async def sub(self, backend, key, identifier): + return await self.subscribe(backend, key, identifier) + + async def unsub(self, backend, key, identifier): + return await self.unsubscribe(backend, key, identifier) + async def dispatch(self, backend_str: str, key: Any, *args, **kwargs): """Dispatch an event to the backend.