diff --git a/tildes/tildes/views/message.py b/tildes/tildes/views/message.py index 4c1b5fb..e660fb0 100644 --- a/tildes/tildes/views/message.py +++ b/tildes/tildes/views/message.py @@ -7,7 +7,7 @@ from pyramid.httpexceptions import HTTPFound from pyramid.request import Request from pyramid.view import view_config from sqlalchemy.dialects.postgresql import array -from sqlalchemy.sql.expression import and_, desc, or_ +from sqlalchemy.sql.expression import and_, or_ from webargs.pyramidparser import use_kwargs from tildes.models.message import MessageConversation, MessageReply @@ -39,10 +39,11 @@ def get_user_messages(request: Request) -> dict: ), ) ) - .order_by(desc(MessageConversation.last_reply_time)) .all() ) + conversations.sort(key=lambda c: c.last_activity_time, reverse=True) + return {"conversations": conversations} @@ -56,10 +57,11 @@ def get_user_unread_messages(request: Request) -> dict: array([request.user.user_id]) ) ) - .order_by(desc(MessageConversation.last_reply_time)) .all() ) + conversations.sort(key=lambda c: c.last_activity_time, reverse=True) + return {"conversations": conversations} @@ -79,10 +81,11 @@ def get_user_sent_messages(request: Request) -> dict: ), ) ) - .order_by(desc(MessageConversation.last_reply_time)) .all() ) + conversations.sort(key=lambda c: c.last_activity_time, reverse=True) + return {"conversations": conversations}