display user avatar in shared chat messages

This commit is contained in:
CREDO23 2026-01-14 19:46:37 +02:00
parent dcd36166fc
commit 83d6b735fa
4 changed files with 98 additions and 107 deletions

View file

@ -411,13 +411,9 @@ async def get_thread_messages(
Requires CHATS_READ permission.
"""
try:
# Get thread with messages and their authors
# Get thread first
result = await session.execute(
select(NewChatThread)
.options(
selectinload(NewChatThread.messages).selectinload(NewChatMessage.author)
)
.filter(NewChatThread.id == thread_id)
select(NewChatThread).filter(NewChatThread.id == thread_id)
)
thread = result.scalars().first()
@ -436,6 +432,15 @@ async def get_thread_messages(
# Check thread-level access based on visibility
await check_thread_access(session, thread, user)
# Get messages with their authors loaded
messages_result = await session.execute(
select(NewChatMessage)
.options(selectinload(NewChatMessage.author))
.filter(NewChatMessage.thread_id == thread_id)
.order_by(NewChatMessage.created_at)
)
db_messages = messages_result.scalars().all()
# Return messages in the format expected by assistant-ui
messages = [
NewChatMessageRead(
@ -448,7 +453,7 @@ async def get_thread_messages(
author_display_name=msg.author.display_name if msg.author else None,
author_avatar_url=msg.author.avatar_url if msg.author else None,
)
for msg in thread.messages
for msg in db_messages
]
return ThreadHistoryLoadResponse(messages=messages)