1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import test from 'node:test';
import { patchStructures } from '../src/compat.js';
import * as ser from '../src/serialize.js';
const require = createRequire(import.meta.url);
test('MsgKey with $1 (WA Web 2.3000.104x) recovers _serialized in Message and Reaction', () => {
patchStructures();
patchStructures(); // idempotent
const S = require('whatsapp-web.js/src/structures/index.js');
const key = { fromMe: false, remote: '5491122334455@c.us', id: '3EB0AAA1', self: 'in', $1: 'false_5491122334455@c.us_3EB0AAA1' };
const m = new S.Message(null, { id: { ...key }, body: 'hola', t: 1789500000, type: 'chat', from: key.remote, to: 'yo@c.us' });
assert.equal(m.id._serialized, key.$1);
assert.equal(ser.message(m).id, key.$1);
const r = new S.Reaction(null, { msgKey: { ...key, $1: 'x' }, parentMsgKey: { ...key }, reactionText: '👍', timestamp: 1 });
assert.equal(r.msgId._serialized, key.$1);
// IDs that already have _serialized are left alone
const old = new S.Message(null, { id: { ...key, _serialized: 'old' }, body: '', t: 1, type: 'chat' });
assert.equal(old.id._serialized, 'old');
});
|