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 5701d6192..22d1c7f08 100644 --- a/apps/api/libs/handlers/src/chats/list_chats_handler.rs +++ b/apps/api/libs/handlers/src/chats/list_chats_handler.rs @@ -78,7 +78,7 @@ pub async fn list_chats_handler( request: ListChatsRequest, user: &AuthenticatedUser, ) -> Result> { - use database::schema::{asset_permissions, chats, users}; + use database::schema::{asset_permissions, chats, messages, users}; let mut conn = get_pg_pool().get().await?; @@ -101,11 +101,26 @@ pub async fn list_chats_handler( Vec::new() // If admin view, we'll show all chats anyway }; + let user_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::request_message.is_not_null()) + .filter(messages::deleted_at.is_null()) + .count(); + + let total_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::deleted_at.is_null()) + .count(); + // Start building the query let mut query = chats::table .inner_join(users::table.on(chats::created_by.eq(users::id))) .filter(chats::deleted_at.is_null()) .filter(chats::title.ne("")) // Filter out empty titles + .filter( + user_message_count.gt(0) + .or(total_message_count.gt(1)) + ) .into_boxed(); // Add user filter if not admin view @@ -173,4 +188,4 @@ pub async fn list_chats_handler( }; Ok(items) -} \ No newline at end of file +} 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 4ce45bf8e..507dccafa 100644 --- a/apps/api/libs/handlers/src/logs/list_logs_handler.rs +++ b/apps/api/libs/handlers/src/logs/list_logs_handler.rs @@ -69,10 +69,21 @@ pub async fn list_logs_handler( request: ListLogsRequest, organization_id: Uuid, ) -> Result { - use database::schema::{chats, users}; + use database::schema::{chats, messages, users}; let mut conn = get_pg_pool().get().await?; + let user_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::request_message.is_not_null()) + .filter(messages::deleted_at.is_null()) + .count(); + + let total_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::deleted_at.is_null()) + .count(); + // Start building the query let mut query = chats::table .inner_join(users::table.on(chats::created_by.eq(users::id))) @@ -80,6 +91,10 @@ pub async fn list_logs_handler( .filter(chats::organization_id.eq(organization_id)) .filter(chats::title.ne("")) // Filter out empty titles .filter(chats::title.ne(" ")) // Filter out single space + .filter( + user_message_count.gt(0) + .or(total_message_count.gt(1)) + ) .into_boxed(); // Calculate offset based on page number