From 728f2251dee67dd3d2fcb96a4b15f065b8a1b15a Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 16 Feb 2019 21:51:11 -0300 Subject: [PATCH] storage: add optional user_id kwarg to ignore recipient - storage: give gdm id as str --- litecord/storage.py | 14 ++++++++++---- litecord/user_storage.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/litecord/storage.py b/litecord/storage.py index 54fb8e6..4554589 100644 --- a/litecord/storage.py +++ b/litecord/storage.py @@ -367,20 +367,24 @@ class Storage: return [r['member_id'] for r in user_ids] - async def _gdm_recipients(self, channel_id: int) -> List[int]: + async def _gdm_recipients(self, channel_id: int, + reference_id: int = None) -> List[int]: """Get the list of users that are recipients of the given Group DM.""" recipients = await self.gdm_recipient_ids(channel_id) res = [] for user_id in recipients: + if user_id == reference_id: + continue + res.append( await self.get_user(user_id) ) return res - async def get_channel(self, channel_id: int) -> Dict[str, Any]: + async def get_channel(self, channel_id: int, **kwargs) -> Dict[str, Any]: """Fetch a single channel's information.""" chan_type = await self.get_chan_type(channel_id) ctype = ChannelType(chan_type) @@ -430,14 +434,16 @@ class Storage: return drow elif ctype == ChannelType.GROUP_DM: gdm_row = await self.db.fetchrow(""" - SELECT id, owner_id::text, name, icon + SELECT id::text, owner_id::text, name, icon FROM group_dm_channels WHERE id = $1 """, channel_id) drow = dict(gdm_row) drow['type'] = chan_type - drow['recipients'] = await self._gdm_recipients(channel_id) + drow['recipients'] = await self._gdm_recipients( + channel_id, kwargs.get('user_id') + ) drow['last_message_id'] = await self.chan_last_message_str( channel_id ) diff --git a/litecord/user_storage.py b/litecord/user_storage.py index 36e7cad..baaeb2a 100644 --- a/litecord/user_storage.py +++ b/litecord/user_storage.py @@ -357,7 +357,7 @@ class UserStorage: for gdm_id in gdm_ids: res.append( - await self.storage.get_channel(gdm_id) + await self.storage.get_channel(gdm_id, user_id=user_id) ) return res