mirror of https://gitlab.com/litecord/litecord.git
user_storage: handle edge case when user is not in guilds
This commit is contained in:
parent
b079dd428a
commit
3c46948837
|
|
@ -495,7 +495,7 @@ async def _del_from_table(table: str, user_id: int):
|
||||||
@bp.route('/@me/delete', methods=['POST'])
|
@bp.route('/@me/delete', methods=['POST'])
|
||||||
async def delete_account():
|
async def delete_account():
|
||||||
"""Delete own account.
|
"""Delete own account.
|
||||||
|
|
||||||
This removes the account from all tables and
|
This removes the account from all tables and
|
||||||
forces all currently connected clients to reconnect.
|
forces all currently connected clients to reconnect.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,16 @@ class UserStorage:
|
||||||
async def get_mutual_guilds(self, user_id: int, peer_id: int) -> List[int]:
|
async def get_mutual_guilds(self, user_id: int, peer_id: int) -> List[int]:
|
||||||
"""Get a list of guilds two separate users
|
"""Get a list of guilds two separate users
|
||||||
have in common."""
|
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("""
|
mutual_guilds = await self.db.fetch("""
|
||||||
SELECT guild_id FROM members WHERE user_id = $1
|
SELECT guild_id FROM members WHERE user_id = $1
|
||||||
INTERSECT
|
INTERSECT
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue