From 3c4694883776efd8df95e0e07c0f55caea824be1 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 5 Feb 2019 18:12:06 -0300 Subject: [PATCH] user_storage: handle edge case when user is not in guilds --- litecord/blueprints/users.py | 2 +- litecord/user_storage.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/litecord/blueprints/users.py b/litecord/blueprints/users.py index 2ed1076..8fbb270 100644 --- a/litecord/blueprints/users.py +++ b/litecord/blueprints/users.py @@ -495,7 +495,7 @@ async def _del_from_table(table: str, user_id: int): @bp.route('/@me/delete', methods=['POST']) async def delete_account(): """Delete own account. - + This removes the account from all tables and forces all currently connected clients to reconnect. """ diff --git a/litecord/user_storage.py b/litecord/user_storage.py index 1f0e2bd..972e16a 100644 --- a/litecord/user_storage.py +++ b/litecord/user_storage.py @@ -291,6 +291,16 @@ class UserStorage: async def get_mutual_guilds(self, user_id: int, peer_id: int) -> List[int]: """Get a list of guilds two separate users have in common.""" + if user_id == peer_id: + # if we are trying to query the mutual guilds with ourselves, we + # only need to give the list of guilds we are on. + + # doing the INTERSECT has some edge-cases that can fuck up testing, + # such as a user querying its own profile card while they are + # not in any guilds. + + return await self.get_user_guilds(user_id) or [0] + mutual_guilds = await self.db.fetch(""" SELECT guild_id FROM members WHERE user_id = $1 INTERSECT