app: sort conversations by last user message

Conversations in the sidebar were being sorted by the timestamp of the
last message (including assistant responses). This changes the sorting
to use only user messages, matching the behavior of ChatGPT and Claude.

Fixes #12958
This commit is contained in:
Nathan Nguyen
2025-12-15 03:32:28 -05:00
parent 4ff8a691bc
commit 7cdd3c9d42
2 changed files with 4 additions and 3 deletions

View File

@@ -513,7 +513,7 @@ func (db *database) getAllChats() ([]Chat, error) {
WHERE role = 'user' WHERE role = 'user'
GROUP BY chat_id GROUP BY chat_id
) first_msg ON c.id = first_msg.chat_id ) first_msg ON c.id = first_msg.chat_id
LEFT JOIN messages m ON c.id = m.chat_id LEFT JOIN messages m ON c.id = m.chat_id AND m.role = 'user'
GROUP BY c.id, c.title, c.created_at, first_msg.content GROUP BY c.id, c.title, c.created_at, first_msg.content
ORDER BY last_updated DESC ORDER BY last_updated DESC
` `

View File

@@ -1365,8 +1365,9 @@ func chatInfoFromChat(chat store.Chat) responses.ChatInfo {
if msg.Role == "user" && userExcerpt == "" { if msg.Role == "user" && userExcerpt == "" {
userExcerpt = msg.Content userExcerpt = msg.Content
} }
// update the updated at time // update the updated at time based on user messages only
if msg.UpdatedAt.After(updatedAt) { // this ensures conversations are sorted by last user message, not last response
if msg.Role == "user" && msg.UpdatedAt.After(updatedAt) {
updatedAt = msg.UpdatedAt updatedAt = msg.UpdatedAt
} }
} }