Fix: Preservar alias al recargar lista de chats
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m9s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m9s
El endpoint chats.get no retornaba el campo alias, lo que causaba que al recargar los chats (cuando llega un mensaje nuevo) el alias se perdiera. Cambios: - Agregar alias a la query de chats.get - Priorizar alias sobre name en la respuesta - Incluir originalName para referencia en el modal
This commit is contained in:
@@ -8,6 +8,7 @@ interface ChatRow {
|
||||
id: string
|
||||
jid: string
|
||||
name: string | null
|
||||
alias: string | null
|
||||
is_group: boolean
|
||||
unread_count: number
|
||||
last_message_at: Date | null
|
||||
@@ -31,7 +32,7 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
// Get chats with last message and type
|
||||
const result = await query<ChatRow>(
|
||||
`SELECT c.id, c.jid, c.name, c.is_group, c.unread_count, c.last_message_at,
|
||||
`SELECT c.id, c.jid, c.name, c.alias, c.is_group, c.unread_count, c.last_message_at,
|
||||
c.last_message_type,
|
||||
(SELECT COALESCE(content, caption) FROM messages m WHERE m.chat_id = c.id ORDER BY timestamp DESC LIMIT 1) as last_message
|
||||
FROM chats c
|
||||
@@ -43,7 +44,11 @@ export default defineEventHandler(async (event) => {
|
||||
return result.rows.map(row => ({
|
||||
id: row.id,
|
||||
jid: row.jid,
|
||||
name: row.name || row.jid.split('@')[0],
|
||||
// Alias has priority over name
|
||||
name: row.alias || row.name || row.jid.split('@')[0],
|
||||
// Keep original name for reference
|
||||
originalName: row.name || row.jid.split('@')[0],
|
||||
alias: row.alias,
|
||||
isGroup: row.is_group,
|
||||
unreadCount: row.unread_count,
|
||||
lastMessageAt: row.last_message_at,
|
||||
|
||||
Reference in New Issue
Block a user