From 1f36348021753ca7d197cb5c249c874d467fd37b Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 13 Aug 2022 15:53:07 +0200 Subject: [PATCH] Fix DMs section --- app/admin.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/app/admin.py b/app/admin.py index c45575f..960bc83 100644 --- a/app/admin.py +++ b/app/admin.py @@ -497,31 +497,39 @@ async def admin_direct_messages( ) last_from_inbox = ( ( - await db_session.scalars( - select(models.InboxObject) - .where(or_(*convos_with_last_from_inbox)) - .options( - joinedload(models.InboxObject.actor), + ( + await db_session.scalars( + select(models.InboxObject) + .where(or_(*convos_with_last_from_inbox)) + .options( + joinedload(models.InboxObject.actor), + ) ) ) + .unique() + .all() ) - .unique() - .all() + if convos_with_last_from_inbox + else [] ) last_from_outbox = ( ( - await db_session.scalars( - select(models.OutboxObject) - .where(or_(*convos_with_last_from_outbox)) - .options( - joinedload(models.OutboxObject.outbox_object_attachments).options( - joinedload(models.OutboxObjectAttachment.upload) - ), + ( + await db_session.scalars( + select(models.OutboxObject) + .where(or_(*convos_with_last_from_outbox)) + .options( + joinedload( + models.OutboxObject.outbox_object_attachments + ).options(joinedload(models.OutboxObjectAttachment.upload)), + ) ) ) + .unique() + .all() ) - .unique() - .all() + if convos_with_last_from_outbox + else [] ) # Build the template response