From c01764243fe4219ee331d863182553db96c2599e Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Sun, 5 Apr 2026 10:34:48 -0400 Subject: [PATCH] Order conversations by recency and auto-name from first message Conversations are now returned sorted by most recently updated first. New conversations are named using the first 100 characters of the user's initial message instead of a username+timestamp placeholder. Co-Authored-By: Claude Opus 4.6 --- blueprints/conversation/__init__.py | 2 +- blueprints/conversation/logic.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/blueprints/conversation/__init__.py b/blueprints/conversation/__init__.py index 4175eff..1622364 100644 --- a/blueprints/conversation/__init__.py +++ b/blueprints/conversation/__init__.py @@ -275,7 +275,7 @@ async def create_conversation(): async def get_all_conversations(): user_uuid = get_jwt_identity() user = await blueprints.users.models.User.get(id=user_uuid) - conversations = Conversation.filter(user=user) + conversations = Conversation.filter(user=user).order_by("-updated_at") serialized_conversations = await PydListConversation.from_queryset(conversations) return jsonify(serialized_conversations.model_dump()) diff --git a/blueprints/conversation/logic.py b/blueprints/conversation/logic.py index 4586d19..d3d2660 100644 --- a/blueprints/conversation/logic.py +++ b/blueprints/conversation/logic.py @@ -19,6 +19,12 @@ async def add_message_to_conversation( image_key: str | None = None, ) -> ConversationMessage: print(conversation, message, speaker) + + # Name the conversation after the first user message + if speaker == "user" and not await conversation.messages.all().exists(): + conversation.name = message[:100] + await conversation.save() + message = await ConversationMessage.create( text=message, speaker=speaker,