diff --git a/litecord/blueprints/dm_channels.py b/litecord/blueprints/dm_channels.py index 3b395a1..e30effd 100644 --- a/litecord/blueprints/dm_channels.py +++ b/litecord/blueprints/dm_channels.py @@ -24,11 +24,51 @@ from litecord.blueprints.auth import token_check from litecord.blueprints.checks import channel_check from litecord.enums import ChannelType from litecord.errors import BadRequest, Forbidden +from litecord.snowflake import get_snowflake log = Logger(__name__) bp = Blueprint('dm_channels', __name__) +async def _gdm_create(user_id, peer_id) -> int: + """Create a group dm, given two users. + + Returns the new GDM id. + """ + channel_id = get_snowflake() + + # TODO + + return channel_id + + +async def _gdm_add_recipient(channel_id: int, peer_id: int, *, user_id=None): + """Add a recipient to a Group DM. + + Dispatches: + - A system message with the join (depending of user_id) + - A CHANNEL_CREATE to the peer. + - A CHANNEL_UPDATE to all remaining recipients. + """ + + # TODO + pass + + +async def _gdm_remove_recipient(channel_id: int, peer_id: int, *, user_id=None): + """Remove a member from a GDM. + + Dispatches: + - A system message with the leave or forced removal (depending if user_id) + exists or not. + - A CHANNEL_DELETE to the peer. + - A CHANNEL_UPDATE to all remaining recipients. + """ + + # TODO + pass + + @bp.route('//receipients/', methods=['PUT']) async def add_to_group_dm(dm_chan, peer_id): """Adds a member to a group dm OR creates a group dm.""" diff --git a/litecord/storage.py b/litecord/storage.py index d44e035..03b6dfe 100644 --- a/litecord/storage.py +++ b/litecord/storage.py @@ -353,7 +353,7 @@ class Storage: return list(map(_overwrite_convert, overwrite_rows)) - async def _gdm_recipient_ids(self, channel_id: int) -> List[int]: + async def gdm_recipient_ids(self, channel_id: int) -> List[int]: """Get the list of user IDs that are recipients of the given Group DM.""" user_ids = await self.db.fetch(""" @@ -370,7 +370,7 @@ class Storage: async def _gdm_recipients(self, channel_id: int) -> List[int]: """Get the list of users that are recipients of the given Group DM.""" - recipients = await self._gdm_recipient_ids(channel_id) + recipients = await self.gdm_recipient_ids(channel_id) res = [] for user_id in recipients: @@ -435,7 +435,6 @@ class Storage: """, channel_id) drow = dict(gdm_row) - recipients drow['recipients'] = await self._gdm_recipients(channel_id) return drow