fix(whatsapp): migrate inactive jid aliases during reconciliation
This commit is contained in:
+19
-1
@@ -3552,7 +3552,25 @@ async function performWhatsAppTenantSync(tenantId, channel, options = {}) {
|
|||||||
}
|
}
|
||||||
const jid = canonicalWhatsAppJid(rawJid, identity)
|
const jid = canonicalWhatsAppJid(rawJid, identity)
|
||||||
const conversationId = `${channel.id}:${jid}`
|
const conversationId = `${channel.id}:${jid}`
|
||||||
const currentBeforeSync = await getResource(tenantId, 'conversations', conversationId) || rawConversation
|
let canonicalConversation = await getResource(tenantId, 'conversations', conversationId)
|
||||||
|
if (
|
||||||
|
rawConversation
|
||||||
|
&& rawConversationId !== conversationId
|
||||||
|
&& !canonicalConversation
|
||||||
|
&& !await getResource(tenantId, 'conversation-tombstones', conversationId)
|
||||||
|
) {
|
||||||
|
canonicalConversation = await putResource(tenantId, 'conversations', {
|
||||||
|
...rawConversation,
|
||||||
|
id: conversationId,
|
||||||
|
whatsappJid: jid,
|
||||||
|
whatsappJidAliases: Array.from(new Set([
|
||||||
|
...(rawConversation.whatsappJidAliases || []),
|
||||||
|
rawJid,
|
||||||
|
jid,
|
||||||
|
])),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const currentBeforeSync = canonicalConversation || rawConversation
|
||||||
const currentCustomer = currentBeforeSync?.customerId
|
const currentCustomer = currentBeforeSync?.customerId
|
||||||
? await getResource(tenantId, 'customers', currentBeforeSync.customerId)
|
? await getResource(tenantId, 'customers', currentBeforeSync.customerId)
|
||||||
: rawCustomer
|
: rawCustomer
|
||||||
|
|||||||
Reference in New Issue
Block a user