Browse Source

Fix sorting of message lists

This should really be done on the database end, but this is a simple fix
for the sorting being wrong (due to last_reply_time not being set for
single-message conversations).
merge-requests/37/head
Deimos 6 years ago
parent
commit
d6120c4685
  1. 11
      tildes/tildes/views/message.py

11
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}

Loading…
Cancel
Save