dm_channels: fix some pubsub stuff

- pubsub.channel: make gdm_recipient_view a public function
This commit is contained in:
Luna 2019-02-17 00:16:26 -03:00
parent da669e5fb2
commit 7f7c71b3eb
2 changed files with 16 additions and 7 deletions

View File

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

View File

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