blueprints.channels: fix close_channel for dms

- dispatcher: add sub() and unsub() alias methods
This commit is contained in:
Luna Mendes 2018-10-11 23:09:27 -03:00
parent 20332805b8
commit 919e5ff903
2 changed files with 13 additions and 3 deletions

View File

@ -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:

View File

@ -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.