user_storage: handle edge case when user is not in guilds

This commit is contained in:
Luna 2019-02-05 18:12:06 -03:00
parent b079dd428a
commit 3c46948837
2 changed files with 11 additions and 1 deletions

View File

@ -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.
"""

View File

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