From 9896b5cc9017b3bd7d7ef0bbb70fd32391b679db Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 04:12:13 +0000 Subject: [PATCH] Replace 'Unknown' user name fallback with email address - Update Rust handlers to use user_email instead of 'Unknown' fallback - Add user_email field to MessageWithUser and ChatWithUser structs - Update database queries to select user email field - Update TypeScript chat-helpers to use email fallback - Maintain final fallback to 'Unknown'/'Unknown User' if email is null Fixes BUS-1457 Co-Authored-By: Dallin Bentley --- apps/api/libs/handlers/src/chats/get_chat_handler.rs | 6 ++++-- apps/api/libs/handlers/src/chats/list_chats_handler.rs | 7 +++++-- apps/api/libs/handlers/src/logs/list_logs_handler.rs | 4 +++- apps/server/src/api/v2/chats/services/chat-helpers.ts | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/api/libs/handlers/src/chats/get_chat_handler.rs b/apps/api/libs/handlers/src/chats/get_chat_handler.rs index ee61bbfe5..04b9310eb 100644 --- a/apps/api/libs/handlers/src/chats/get_chat_handler.rs +++ b/apps/api/libs/handlers/src/chats/get_chat_handler.rs @@ -43,6 +43,7 @@ pub struct MessageWithUser { pub updated_at: DateTime, pub user_id: Uuid, pub user_name: Option, + pub user_email: String, pub user_avatar_url: Option, pub feedback: Option, pub is_completed: bool, @@ -137,6 +138,7 @@ pub async fn get_chat_handler( messages::updated_at, users::id, users::name.nullable(), + users::email, users::avatar_url.nullable(), messages::feedback.nullable(), messages::is_completed, @@ -274,7 +276,7 @@ pub async fn get_chat_handler( Some(ChatUserMessage { request: Some(request_message), sender_id: msg.user_id, - sender_name: msg.user_name.unwrap_or_else(|| "Unknown".to_string()), + sender_name: msg.user_name.unwrap_or_else(|| msg.user_email.clone()), sender_avatar: msg.user_avatar_url, }) } else { @@ -353,7 +355,7 @@ pub async fn get_chat_handler( thread_messages, false, // is_favorited not implemented in current schema thread.user_id.to_string(), - thread.user_name.unwrap_or_else(|| "Unknown".to_string()), + thread.user_name.unwrap_or_else(|| thread.user_email.clone()), created_by_avatar, ); diff --git a/apps/api/libs/handlers/src/chats/list_chats_handler.rs b/apps/api/libs/handlers/src/chats/list_chats_handler.rs index 554f58926..520b22dcd 100644 --- a/apps/api/libs/handlers/src/chats/list_chats_handler.rs +++ b/apps/api/libs/handlers/src/chats/list_chats_handler.rs @@ -63,6 +63,7 @@ struct ChatWithUser { pub most_recent_version_number: Option, // User fields pub user_name: Option, + pub user_email: String, pub user_avatar_url: Option, } @@ -144,6 +145,7 @@ pub async fn list_chats_handler( chats::most_recent_file_type, chats::most_recent_version_number, users::name.nullable(), + users::email, users::avatar_url.nullable(), )) .load::(&mut conn) @@ -235,6 +237,7 @@ pub async fn list_chats_handler( chats::most_recent_file_type, chats::most_recent_version_number, users::name.nullable(), + users::email, users::avatar_url.nullable(), )) .order_by(chats::updated_at.desc()) @@ -258,7 +261,7 @@ pub async fn list_chats_handler( updated_at: chat.updated_at.to_rfc3339(), created_by: chat.created_by.to_string(), created_by_id: chat.created_by.to_string(), - created_by_name: chat.user_name.unwrap_or_else(|| "Unknown".to_string()), + created_by_name: chat.user_name.unwrap_or_else(|| chat.user_email.clone()), created_by_avatar: chat.user_avatar_url, last_edited: chat.updated_at.to_rfc3339(), latest_file_id: chat.most_recent_file_id.map(|id| id.to_string()), @@ -280,7 +283,7 @@ pub async fn list_chats_handler( updated_at: chat.updated_at.to_rfc3339(), created_by: chat.created_by.to_string(), created_by_id: chat.created_by.to_string(), - created_by_name: chat.user_name.unwrap_or_else(|| "Unknown".to_string()), + created_by_name: chat.user_name.unwrap_or_else(|| chat.user_email.clone()), created_by_avatar: chat.user_avatar_url, last_edited: chat.updated_at.to_rfc3339(), latest_file_id: chat.most_recent_file_id.map(|id| id.to_string()), diff --git a/apps/api/libs/handlers/src/logs/list_logs_handler.rs b/apps/api/libs/handlers/src/logs/list_logs_handler.rs index 09d65fabe..cc4d0f7a0 100644 --- a/apps/api/libs/handlers/src/logs/list_logs_handler.rs +++ b/apps/api/libs/handlers/src/logs/list_logs_handler.rs @@ -55,6 +55,7 @@ struct ChatWithUser { pub most_recent_version_number: Option, // User fields pub user_name: Option, + pub user_email: String, pub user_avatar_url: Option, } @@ -116,6 +117,7 @@ pub async fn list_logs_handler( chats::most_recent_file_type, chats::most_recent_version_number, users::name.nullable(), + users::email, users::avatar_url.nullable(), )) .load::(&mut conn) @@ -135,7 +137,7 @@ pub async fn list_logs_handler( updated_at: chat.updated_at.to_rfc3339(), created_by: chat.created_by.to_string(), created_by_id: chat.created_by.to_string(), - created_by_name: chat.user_name.unwrap_or_else(|| "Unknown".to_string()), + created_by_name: chat.user_name.unwrap_or_else(|| chat.user_email.clone()), created_by_avatar: chat.user_avatar_url, last_edited: chat.updated_at.to_rfc3339(), latest_file_id: chat.most_recent_file_id.map(|id| id.to_string()), diff --git a/apps/server/src/api/v2/chats/services/chat-helpers.ts b/apps/server/src/api/v2/chats/services/chat-helpers.ts index 0932b3821..0c76d2310 100644 --- a/apps/server/src/api/v2/chats/services/chat-helpers.ts +++ b/apps/server/src/api/v2/chats/services/chat-helpers.ts @@ -114,7 +114,7 @@ export function buildChatWithMessages( const messageIds: string[] = new Array(messageCount); // Cache user info to avoid repeated property access - const userName = user?.name || 'Unknown User'; + const userName = user?.name || user?.email || 'Unknown User'; const userAvatar = user?.avatarUrl || undefined; // Single iteration with optimized object creation