mirror of https://gitlab.com/litecord/litecord.git
storage: add optional user_id kwarg to ignore recipient
- storage: give gdm id as str
This commit is contained in:
parent
83108bc367
commit
728f2251de
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue