diff --git a/litecord/blueprints/dm_channels.py b/litecord/blueprints/dm_channels.py index 1f0f4cc..a79ed8b 100644 --- a/litecord/blueprints/dm_channels.py +++ b/litecord/blueprints/dm_channels.py @@ -26,6 +26,7 @@ from litecord.enums import ChannelType, MessageType from litecord.errors import BadRequest, Forbidden from litecord.snowflake import get_snowflake from litecord.system_messages import send_sys_message +from litecord.pubsub.channel import gdm_recipient_view log = Logger(__name__) bp = Blueprint('dm_channels', __name__) @@ -85,8 +86,14 @@ async def _gdm_add_recipient(channel_id: int, peer_id: int, *, user_id=None): await _raw_gdm_add(channel_id, peer_id) 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) + + # the reasoning behind gdm_recipient_view is in its docstring. + await app.dispatcher.dispatch( + 'user', peer_id, 'CHANNEL_CREATE', gdm_recipient_view(chan, peer_id)) + + await app.dispatcher.dispatch( + 'channel', channel_id, 'CHANNEL_UPDATE', chan) + await app.dispatcher.sub('channel', peer_id) if user_id: @@ -108,7 +115,11 @@ async def _gdm_remove_recipient(channel_id: int, peer_id: int, *, user_id=None): await _raw_gdm_remove(channel_id, peer_id) chan = await app.storage.get_channel(channel_id) - await app.dispatcher.dispatch('user', peer_id, 'CHANNEL_DELETE', chan) + await app.dispatcher.dispatch( + 'user', peer_id, 'CHANNEL_DELETE', gdm_recipient_view(chan, user_id)) + + await app.dispatcher.unsub('channel', peer_id) + await app.dispatcher.dispatch( 'channel', channel_id, 'CHANNEL_RECIPIENT_REMOVE', { 'channel_id': str(channel_id), @@ -116,8 +127,6 @@ 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, diff --git a/litecord/pubsub/channel.py b/litecord/pubsub/channel.py index 3f805b4..2b32a1d 100644 --- a/litecord/pubsub/channel.py +++ b/litecord/pubsub/channel.py @@ -28,7 +28,7 @@ from litecord.utils import index_by_func log = Logger(__name__) -def _recipient_view(orig: dict, user_id: int) -> dict: +def gdm_recipient_view(orig: dict, user_id: int) -> dict: """Create a copy of the original channel object that doesn't show the user we are dispatching it to. @@ -91,7 +91,7 @@ class ChannelDispatcher(DispatcherWithState): # we edit the channel payload so it doesn't show # the user as a recipient - new_data = _recipient_view(data, user_id) + new_data = gdm_recipient_view(data, user_id) cur_sess = await self._dispatch_states( states, event, new_data) else: