fix: support serialized message ID fallbacks
Some checks failed
Lint / ESLint (push) Has been cancelled
Tests / Tests (push) Has been cancelled

This commit is contained in:
Eddy de Vink 2026-08-17 18:17:54 +02:00
commit 2dd7653898

View file

@ -934,18 +934,23 @@ exports.LoadUtils = () => {
};
/**
* The serialized id of a message key, tolerating WhatsApp Web having renamed the key's
* `_serialized` property to `$1`. Reading the old name now returns `undefined`, which reaches
* IndexedDB as a `.get(undefined)` and throws
* `DataError: Failed to execute 'get' on 'IDBObjectStore': No key or key range specified.`
* `_serialized` is preferred so nothing changes wherever it is still present (chat ids, for
* example, are unaffected by the rename). Returns undefined when neither exists, so callers can
* skip the lookup instead of querying a store with a nullish key.
* Returns a serialized message-key ID across WhatsApp Web ID shapes.
* @param {Object} key a message key, e.g. `chat.lastReceivedKey` or a raw `msg.id`
* @returns {string|undefined}
*/
window.WWebJS.getMsgKeyId = (key) =>
key?._serialized ?? key?.$1 ?? undefined;
window.WWebJS.getMsgKeyId = (key) => {
if (!key) return undefined;
if (key._serialized) return key._serialized;
if (key.$1) return key.$1;
if (
typeof key.fromMe !== 'undefined' &&
typeof key.remote === 'string' &&
typeof key.id === 'string'
) {
return `${key.fromMe}_${key.remote}_${key.id}`;
}
return undefined;
};
window.WWebJS.getChats = async () => {
const chats = window.require('WAWebCollections').Chat.getModelsArray();