fix(wa-inbox): esvazia a lista de chats quando não há instância ativa
Complementa o fix anterior: no mount, loadChats podia rodar com o activeInstanceId persistido (stale) antes de loadInstances validar, deixando os chats na tela mesmo após o reset. Agora o efeito faz setChats([]) quando não há instância ativa. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -61,7 +61,7 @@ function chatToLegacy(c: ReturnType<typeof useChatStore.getState>['chats'][0]):
|
||||
is_pinned: c.isPinned,
|
||||
is_archived: c.isArchived,
|
||||
bot_paused: c.botPaused ?? null,
|
||||
labels: [],
|
||||
labels: (c as any).labels ?? [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ function messagesToLegacy(msgs: ReturnType<typeof useChatStore.getState>['messag
|
||||
quoted_message_text: m.replyTo?.body ?? null,
|
||||
quoted_participant: m.replyTo ? (m.replyTo.fromMe ? 'me' : null) : null,
|
||||
participant: m.pushName ?? null,
|
||||
reactions: m.reactions ?? null,
|
||||
senderJid: m.senderJid ?? null,
|
||||
sender_jid: m.senderJid ?? null,
|
||||
remote_jid: m.chatId,
|
||||
@@ -118,7 +119,9 @@ export function useNewInboxBridge() {
|
||||
// ── Carregar chats quando instância ativa muda ─────────────────────────────
|
||||
useEffect(() => {
|
||||
const { activeInstanceId } = instanceStore
|
||||
if (!activeInstanceId) return
|
||||
// Sem instância ativa (ex.: superadmin, ou instância resetada por não ser
|
||||
// acessível) → esvazia a lista para NÃO deixar chats de outra sessão na tela.
|
||||
if (!activeInstanceId) { chatStore.setChats([]); return }
|
||||
chatStore.loadChats(activeInstanceId)
|
||||
socketService.joinInstance(activeInstanceId)
|
||||
// Reconcilia nomes em background (cache 30min — leve em escala)
|
||||
|
||||
Reference in New Issue
Block a user