whatsapp-store-db 1.3.65 → 1.3.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/message.js +36 -1
- package/package.json +1 -1
package/dist/handlers/message.js
CHANGED
|
@@ -9,9 +9,24 @@ const getKeyAuthor = (key) => ((key === null || key === void 0 ? void 0 : key.fr
|
|
|
9
9
|
* Stub messages are system notifications (e.g., E2E encryption notices, message deletions)
|
|
10
10
|
* that have a messageStubType but no message body.
|
|
11
11
|
* These don't contain useful chat content and should be skipped.
|
|
12
|
+
*
|
|
13
|
+
* Exception: CTWA (Click-to-WhatsApp) placeholder stubs (messageStubType=2,
|
|
14
|
+
* stubParam="Message absent from node") are saved as placeholder records so
|
|
15
|
+
* there's a trace of the customer message even if PDO recovery fails.
|
|
16
|
+
* The record will be updated with actual content if recovery succeeds later.
|
|
12
17
|
*/
|
|
13
18
|
const isEmptyStubMessage = (message) => {
|
|
14
|
-
|
|
19
|
+
var _a;
|
|
20
|
+
if (message.messageStubType == null || message.messageStubType === 0)
|
|
21
|
+
return false;
|
|
22
|
+
if (message.message)
|
|
23
|
+
return false;
|
|
24
|
+
// Allow CTWA placeholder stubs through — save as placeholder record
|
|
25
|
+
const stubParam = (_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0];
|
|
26
|
+
if (message.messageStubType === 2 && stubParam === 'Message absent from node') {
|
|
27
|
+
return false; // Not "empty" for our purposes — save it
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
15
30
|
};
|
|
16
31
|
/**
|
|
17
32
|
* Checks if a message is a protocol message that should not be stored.
|
|
@@ -378,6 +393,26 @@ function messageHandler(sessionId, event, getJid = undefined) {
|
|
|
378
393
|
validatedFieldCount: Object.keys(validatedData).length
|
|
379
394
|
}, 'Message data was filtered during validation');
|
|
380
395
|
}
|
|
396
|
+
// CTWA stub cleanup: when a recovered message arrives with a phone number JID,
|
|
397
|
+
// delete any existing stub record saved under the LID JID (different remoteJid, same id).
|
|
398
|
+
// This happens because the stub is saved with @lid before LID resolution,
|
|
399
|
+
// and the recovered message arrives with @s.whatsapp.net after PDO resolves the LID.
|
|
400
|
+
if (message.key.id && message.message && jid.includes('@s.whatsapp.net')) {
|
|
401
|
+
const altJid = message.key.remoteJidAlt;
|
|
402
|
+
if (altJid && altJid.endsWith('@lid')) {
|
|
403
|
+
try {
|
|
404
|
+
const deleted = await prisma.message.deleteMany({
|
|
405
|
+
where: { id: message.key.id, remoteJid: altJid, sessionId },
|
|
406
|
+
});
|
|
407
|
+
if (deleted.count > 0) {
|
|
408
|
+
logger.info({ messageId: message.key.id, lidJid: altJid, phoneJid: jid }, 'CTWA: Cleaned up LID stub record after PDO recovery');
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
catch (cleanupErr) {
|
|
412
|
+
logger.error({ error: cleanupErr, messageId: message.key.id }, 'CTWA: Failed to clean up LID stub record');
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
381
416
|
await (0, utils_1.retryDatabaseOperation)(() => prisma.message.upsert({
|
|
382
417
|
select: { pkId: true },
|
|
383
418
|
create: Object.assign(Object.assign({}, validatedData), { remoteJid: jid, id: message.key.id, sessionId }),
|