Sort by most recent chatIDs (#9946)

When we `lazy_load` iMessage chats, return chats w/ most recent msg
first (matches what is visualized in app).
This commit is contained in:
Lance Martin 2023-09-03 15:00:20 -07:00 committed by GitHub
parent cf5a50469f
commit 387813bfb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,8 +108,13 @@ class IMessageChatLoader(chat_loaders.BaseChatLoader):
) from e
cursor = conn.cursor()
# Fetch the list of chat IDs
cursor.execute("SELECT ROWID FROM chat")
# Fetch the list of chat IDs sorted by time (most recent first)
query = """SELECT chat_id
FROM message
JOIN chat_message_join ON message.ROWID = chat_message_join.message_id
GROUP BY chat_id
ORDER BY MAX(date) DESC;"""
cursor.execute(query)
chat_ids = [row[0] for row in cursor.fetchall()]
for chat_id in chat_ids: