fix: support serialized message ID fallbacks
This commit is contained in:
parent
c3a6092bea
commit
2dd7653898
1 changed files with 14 additions and 9 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue