@badzz88/baileys 8.5.7 → 8.5.9

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.
Files changed (142) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +284 -264
  3. package/WAProto/index.js +5 -5
  4. package/engine-requirements.js +7 -15
  5. package/lib/Defaults/index.js +130 -187
  6. package/lib/Signal/Group/ciphertext-message.js +11 -14
  7. package/lib/Signal/Group/group-session-builder.js +29 -91
  8. package/lib/Signal/Group/group_cipher.js +81 -88
  9. package/lib/Signal/Group/index.js +12 -136
  10. package/lib/Signal/Group/keyhelper.js +15 -70
  11. package/lib/Signal/Group/sender-chain-key.js +25 -31
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
  13. package/lib/Signal/Group/sender-key-message.js +65 -68
  14. package/lib/Signal/Group/sender-key-name.js +41 -43
  15. package/lib/Signal/Group/sender-key-record.js +40 -43
  16. package/lib/Signal/Group/sender-key-state.js +83 -96
  17. package/lib/Signal/Group/sender-message-key.js +25 -29
  18. package/lib/Signal/libsignal.js +425 -453
  19. package/lib/Signal/lid-mapping.js +276 -259
  20. package/lib/Socket/Client/index.js +3 -30
  21. package/lib/Socket/Client/types.js +10 -12
  22. package/lib/Socket/Client/websocket.js +53 -61
  23. package/lib/Socket/business.js +379 -422
  24. package/lib/Socket/chats.js +1193 -1816
  25. package/lib/Socket/communities.js +431 -549
  26. package/lib/Socket/graphql.js +672 -612
  27. package/lib/Socket/groups.js +374 -764
  28. package/lib/Socket/index.js +17 -38
  29. package/lib/Socket/interop.js +417 -503
  30. package/lib/Socket/messages-recv.js +1915 -2441
  31. package/lib/Socket/messages-send.js +1213 -1630
  32. package/lib/Socket/mex.js +9 -15
  33. package/lib/Socket/newsletter.js +746 -808
  34. package/lib/Socket/privacy.js +310 -441
  35. package/lib/Socket/socket.js +1025 -1022
  36. package/lib/Socket/username.js +8 -15
  37. package/lib/Store/index.js +10 -36
  38. package/lib/Store/make-cache-manager-store.js +80 -85
  39. package/lib/Store/make-in-memory-store.js +231 -591
  40. package/lib/Store/make-ordered-dictionary.js +72 -78
  41. package/lib/Store/object-repository.js +28 -25
  42. package/lib/Types/Auth.js +2 -38
  43. package/lib/Types/Bussines.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +8 -4
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +11 -95
  52. package/lib/Types/Mex.js +111 -112
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +3 -2
  56. package/lib/Types/State.js +56 -70
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +26 -55
  59. package/lib/Utils/auth-utils.js +288 -292
  60. package/lib/Utils/browser-utils.js +47 -113
  61. package/lib/Utils/business.js +224 -240
  62. package/lib/Utils/chat-utils.js +869 -1205
  63. package/lib/Utils/companion-reg-client-utils.js +34 -41
  64. package/lib/Utils/crypto.js +107 -144
  65. package/lib/Utils/decode-wa-message.js +308 -518
  66. package/lib/Utils/event-buffer.js +611 -596
  67. package/lib/Utils/generics.js +355 -515
  68. package/lib/Utils/history.js +134 -244
  69. package/lib/Utils/identity-change-handler.js +49 -51
  70. package/lib/Utils/index.js +23 -57
  71. package/lib/Utils/link-preview.js +77 -135
  72. package/lib/Utils/logger.js +3 -9
  73. package/lib/Utils/lt-hash.js +6 -37
  74. package/lib/Utils/make-mutex.js +33 -36
  75. package/lib/Utils/message-composer.js +233 -439
  76. package/lib/Utils/message-retry-manager.js +260 -265
  77. package/lib/Utils/messages-media.js +829 -855
  78. package/lib/Utils/messages.js +961 -2528
  79. package/lib/Utils/noise-handler.js +200 -195
  80. package/lib/Utils/offline-node-processor.js +33 -35
  81. package/lib/Utils/pre-key-manager.js +102 -103
  82. package/lib/Utils/process-message.js +560 -978
  83. package/lib/Utils/reporting-utils.js +253 -257
  84. package/lib/Utils/signal.js +195 -218
  85. package/lib/Utils/stanza-ack.js +29 -31
  86. package/lib/Utils/sticker.js +109 -144
  87. package/lib/Utils/sync-action-utils.js +45 -50
  88. package/lib/Utils/tc-token-utils.js +139 -137
  89. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  90. package/lib/Utils/validate-connection.js +202 -218
  91. package/lib/WABinary/constants.js +1299 -1302
  92. package/lib/WABinary/decode.js +262 -343
  93. package/lib/WABinary/encode.js +4 -12
  94. package/lib/WABinary/generic-utils.js +187 -223
  95. package/lib/WABinary/index.js +6 -33
  96. package/lib/WABinary/jid-utils.js +88 -351
  97. package/lib/WABinary/types.js +2 -2
  98. package/lib/WAM/BinaryInfo.js +9 -12
  99. package/lib/WAM/constants.js +22853 -39486
  100. package/lib/WAM/encode.js +140 -132
  101. package/lib/WAM/index.js +4 -31
  102. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
  103. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
  107. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
  108. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
  109. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
  110. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
  112. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
  113. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
  114. package/lib/WAUSync/Protocols/index.js +12 -39
  115. package/lib/WAUSync/USyncQuery.js +67 -49
  116. package/lib/WAUSync/USyncUser.js +11 -5
  117. package/lib/WAUSync/index.js +3 -31
  118. package/lib/index.js +15 -48
  119. package/package.json +129 -99
  120. package/LICENSE +0 -21
  121. package/lib/Defaults/phonenumber-mcc.json +0 -223
  122. package/lib/Socket/aigroups.js +0 -240
  123. package/lib/Socket/interactive-handler.js +0 -522
  124. package/lib/Socket/managed-account.js +0 -183
  125. package/lib/Socket/registration.js +0 -427
  126. package/lib/Socket/text-router.js +0 -83
  127. package/lib/Types/Newsletter.js +0 -121
  128. package/lib/Utils/command-loader.d.ts +0 -31
  129. package/lib/Utils/command-loader.js +0 -100
  130. package/lib/Utils/consumer-application.js +0 -107
  131. package/lib/Utils/curve25519-js.js +0 -275
  132. package/lib/Utils/group-history.js +0 -60
  133. package/lib/Utils/jid-display-normalization.js +0 -218
  134. package/lib/Utils/meta-ai-msmsg.js +0 -262
  135. package/lib/Utils/native-bridge.js +0 -82
  136. package/lib/Utils/session-pool.d.ts +0 -16
  137. package/lib/Utils/session-pool.js +0 -94
  138. package/lib/Utils/sticker.d.ts +0 -17
  139. package/lib/Utils/view-once-cache.d.ts +0 -9
  140. package/lib/Utils/view-once-cache.js +0 -79
  141. package/lib/Utils/voip-rekey.js +0 -22
  142. package/lib/antiban.js +0 -4637
@@ -1,145 +1,110 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.imageToWebpSticker = exports.videoToWebpSticker = exports.addExifToWebp = void 0
4
- const os = require('os')
5
- const path = require('path')
6
- const fs = require('fs')
7
- const crypto = require('crypto')
8
- const { exec } = require('child_process')
1
+ import { Boom } from '@hapi/boom';
2
+ import { spawn } from 'child_process';
3
+ import { randomUUID } from 'crypto';
9
4
 
10
- /**
11
- * Builds and writes the EXIF metadata WhatsApp expects on sticker webp files
12
- * (pack name / author, shown when a user long-presses a sticker).
13
- * Converts the file to the "extended" (VP8X) WebP container if it isn't already,
14
- * since that's the container format that actually carries an EXIF chunk.
15
- * Returns the new buffer with EXIF attached.
16
- */
17
- const addExifToWebp = async (webpBuffer, { packName = '', packPublisher = '', categories = [] } = {}) => {
18
- const json = {
19
- 'sticker-pack-id': crypto.randomBytes(16).toString('hex'),
20
- 'sticker-pack-name': packName,
21
- 'sticker-pack-publisher': packPublisher,
22
- emojis: categories.length ? categories : ['😀']
23
- }
24
- const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf-8')
25
- // TIFF header + IFD entry pointing at a single custom tag (0x5741 "AW") holding
26
- // the JSON payload -- this is the exact structure WhatsApp's client parses.
27
- const exifAttr = Buffer.from([
28
- 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
29
- 0x00, 0x00, 0x00
30
- ])
31
- exifAttr.writeUIntLE(jsonBuffer.length, 14, 4)
32
- const exifPayload = Buffer.concat([exifAttr, jsonBuffer])
33
- const pad = buf => (buf.length % 2 === 1 ? Buffer.concat([buf, Buffer.from([0x00])]) : buf)
34
- const makeChunk = (tag, data) => {
35
- const sizeField = Buffer.alloc(4)
36
- sizeField.writeUInt32LE(data.length, 0)
37
- return Buffer.concat([Buffer.from(tag, 'ascii'), sizeField, pad(data)])
38
- }
39
- const exifChunk = makeChunk('EXIF', exifPayload)
40
- if (webpBuffer.slice(0, 4).toString('ascii') !== 'RIFF' || webpBuffer.slice(8, 12).toString('ascii') !== 'WEBP') {
41
- throw new Error('addExifToWebp expects a valid WebP buffer')
42
- }
43
- let offset = 12
44
- let vp8xChunk = null
45
- let vp8xOffset = -1
46
- const otherChunks = []
47
- while (offset < webpBuffer.length) {
48
- const tag = webpBuffer.slice(offset, offset + 4).toString('ascii')
49
- const size = webpBuffer.readUInt32LE(offset + 4)
50
- const dataStart = offset + 8
51
- const dataEnd = dataStart + size
52
- const chunkTotal = 8 + size + (size % 2)
53
- if (tag === 'VP8X') {
54
- vp8xChunk = webpBuffer.slice(offset, offset + chunkTotal)
55
- vp8xOffset = offset
56
- } else if (tag !== 'EXIF') {
57
- // drop any pre-existing EXIF chunk, keep everything else (VP8/VP8L/ANIM/ANMF/ICCP/...)
58
- otherChunks.push(webpBuffer.slice(offset, offset + chunkTotal))
59
- }
60
- offset += chunkTotal
61
- }
62
- let flags
63
- let canvasWidth
64
- let canvasHeight
65
- if (vp8xChunk) {
66
- flags = vp8xChunk.readUInt8(8)
67
- canvasWidth = vp8xChunk.readUIntLE(12, 3) + 1
68
- canvasHeight = vp8xChunk.readUIntLE(15, 3) + 1
69
- } else {
70
- flags = 0
71
- let sharp
72
- try {
73
- sharp = require('sharp')
74
- } catch (error) {
75
- throw new Error('addExifToWebp needs the optional "sharp" dependency to read image dimensions')
76
- }
77
- const meta = await sharp(webpBuffer).metadata()
78
- canvasWidth = meta.width
79
- canvasHeight = meta.height
80
- }
81
- flags |= 0x08 // set the "has EXIF metadata" bit
82
- const vp8xData = Buffer.alloc(10)
83
- vp8xData.writeUInt8(flags, 0)
84
- vp8xData.writeUIntLE(canvasWidth - 1, 4, 3)
85
- vp8xData.writeUIntLE(canvasHeight - 1, 7, 3)
86
- const newVp8xChunk = makeChunk('VP8X', vp8xData)
87
- const body = Buffer.concat([newVp8xChunk, ...otherChunks, exifChunk])
88
- const fileSize = Buffer.alloc(4)
89
- fileSize.writeUInt32LE(4 + body.length, 0) // 4 = 'WEBP'
90
- return Buffer.concat([Buffer.from('RIFF', 'ascii'), fileSize, Buffer.from('WEBP', 'ascii'), body])
91
- }
92
- exports.addExifToWebp = addExifToWebp
93
-
94
- /**
95
- * Converts a static image buffer to a WhatsApp sticker-ready webp buffer using `sharp`.
96
- * @param {Buffer} imageBuffer
97
- * @param {{ packName?: string, packPublisher?: string, categories?: string[], quality?: number }} [options]
98
- * @returns {Promise<Buffer>}
99
- */
100
- const imageToWebpSticker = async (imageBuffer, options = {}) => {
101
- let sharp
102
- try {
103
- sharp = require('sharp')
104
- } catch (error) {
105
- throw new Error('imageToWebpSticker requires the optional "sharp" dependency to be installed')
106
- }
107
- const webp = await sharp(imageBuffer)
108
- .resize(512, 512, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } })
109
- .webp({ quality: options.quality ?? 80 })
110
- .toBuffer()
111
- return addExifToWebp(webp, options)
112
- }
113
- exports.imageToWebpSticker = imageToWebpSticker
114
-
115
- /**
116
- * Converts a video buffer to an animated WhatsApp sticker-ready webp buffer.
117
- * Requires the `ffmpeg` binary to be available on PATH.
118
- * @param {Buffer} videoBuffer
119
- * @param {{ packName?: string, packPublisher?: string, categories?: string[], fps?: number, seconds?: number }} [options]
120
- * @returns {Promise<Buffer>}
121
- */
122
- const videoToWebpSticker = async (videoBuffer, options = {}) => {
123
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xazbails-sticker-'))
124
- const inputPath = path.join(tmpDir, 'input.mp4')
125
- const outputPath = path.join(tmpDir, 'output.webp')
126
- fs.writeFileSync(inputPath, videoBuffer)
127
- const fps = options.fps ?? 10
128
- const seconds = options.seconds ?? 5
129
- const cmd =
130
- `ffmpeg -y -i ${inputPath} -t ${seconds} -vf ` +
131
- `"fps=${fps},scale=512:512:force_original_aspect_ratio=decrease,` +
132
- `pad=512:512:(ow-iw)/2:(oh-ih)/2:color=0x00000000,split[a][b];` +
133
- `[a]palettegen=reserve_transparent=1[p];[b][p]paletteuse" ` +
134
- `-loop 0 -preset default -an -vsync 0 ${outputPath}`
135
- try {
136
- await new Promise((resolve, reject) => {
137
- exec(cmd, err => (err ? reject(err) : resolve()))
138
- })
139
- const webp = fs.readFileSync(outputPath)
140
- return await addExifToWebp(webp, options)
141
- } finally {
142
- fs.rmSync(tmpDir, { recursive: true, force: true })
143
- }
144
- }
145
- exports.videoToWebpSticker = videoToWebpSticker
5
+ const runFfmpeg = (input, args) => new Promise((resolve, reject) => {
6
+ const proc = spawn('ffmpeg', ['-hide_banner', '-loglevel', 'error', '-i', 'pipe:0', ...args, 'pipe:1'], { stdio: ['pipe', 'pipe', 'pipe'] });
7
+ const outChunks = [];
8
+ const errChunks = [];
9
+ proc.stdout.on('data', chunk => outChunks.push(chunk));
10
+ proc.stderr.on('data', chunk => errChunks.push(chunk));
11
+ proc.on('error', err => reject(new Boom(`ffmpeg failed to start: ${err.message}`, { statusCode: 500 })));
12
+ proc.on('close', code => {
13
+ if (code !== 0) {
14
+ reject(new Boom(`ffmpeg exited with code ${code}: ${Buffer.concat(errChunks).toString('utf8').slice(0, 500)}`, { statusCode: 500 }));
15
+ return;
16
+ }
17
+ resolve(Buffer.concat(outChunks));
18
+ });
19
+ proc.stdin.on('error', () => { });
20
+ proc.stdin.end(input);
21
+ });
22
+ export const convertToWebp = async (buffer, { animated = false, quality = 60 } = {}) => {
23
+ const scalePad = "scale='min(512,iw)':'min(512,ih)':force_original_aspect_ratio=decrease,format=rgba,pad=512:512:-1:-1:color=#00000000";
24
+ const args = animated
25
+ ? ['-vf', `${scalePad},fps=15`, '-loop', '0', '-preset', 'default', '-an', '-vsync', '0', '-vcodec', 'libwebp', '-q:v', String(quality), '-f', 'webp']
26
+ : ['-vf', `${scalePad}`, '-vframes', '1', '-vcodec', 'libwebp', '-q:v', String(quality), '-f', 'webp'];
27
+ return runFfmpeg(buffer, args);
28
+ };
29
+ const readChunks = (buf) => {
30
+ const chunks = [];
31
+ let offset = 12;
32
+ while (offset + 8 <= buf.length) {
33
+ const fourCC = buf.toString('ascii', offset, offset + 4);
34
+ const size = buf.readUInt32LE(offset + 4);
35
+ const dataStart = offset + 8;
36
+ const data = buf.subarray(dataStart, dataStart + size);
37
+ chunks.push({ fourCC, data });
38
+ offset = dataStart + size + (size % 2);
39
+ }
40
+ return chunks;
41
+ };
42
+ const buildChunk = (fourCC, data) => {
43
+ const header = Buffer.alloc(8);
44
+ header.write(fourCC, 0, 4, 'ascii');
45
+ header.writeUInt32LE(data.length, 4);
46
+ const pad = data.length % 2 === 1 ? Buffer.from([0]) : Buffer.alloc(0);
47
+ return Buffer.concat([header, data, pad]);
48
+ };
49
+ const buildExifChunkData = (json) => {
50
+ const header = Buffer.from([0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00]);
51
+ const payload = Buffer.from(JSON.stringify(json), 'utf8');
52
+ header.writeUInt32LE(payload.length, 14);
53
+ return Buffer.concat([header, payload]);
54
+ };
55
+ export const writeExifToWebp = (webpBuffer, { packId, packName = '', publisher = '', emojis = [], isAvatar = false } = {}) => {
56
+ if (webpBuffer.toString('ascii', 0, 4) !== 'RIFF' || webpBuffer.toString('ascii', 8, 12) !== 'WEBP') {
57
+ throw new Boom('writeExifToWebp: not a valid webp buffer', { statusCode: 400 });
58
+ }
59
+ const chunks = readChunks(webpBuffer);
60
+ const exifData = buildExifChunkData({
61
+ 'sticker-pack-id': packId || randomUUID(),
62
+ 'sticker-pack-name': packName,
63
+ 'sticker-pack-publisher': publisher,
64
+ emojis: emojis.length ? emojis : ['🤖'],
65
+ 'is-avatar-sticker': isAvatar ? 1 : 0
66
+ });
67
+ let vp8x = chunks.find(c => c.fourCC === 'VP8X');
68
+ const otherChunks = chunks.filter(c => c.fourCC !== 'VP8X' && c.fourCC !== 'EXIF');
69
+ if (!vp8x) {
70
+ const img = otherChunks.find(c => c.fourCC === 'VP8 ' || c.fourCC === 'VP8L');
71
+ if (!img) {
72
+ throw new Boom('writeExifToWebp: no VP8/VP8L image data found', { statusCode: 400 });
73
+ }
74
+ let width;
75
+ let height;
76
+ if (img.fourCC === 'VP8 ') {
77
+ width = (img.data.readUInt16LE(6) & 0x3fff);
78
+ height = (img.data.readUInt16LE(8) & 0x3fff);
79
+ }
80
+ else {
81
+ const b = img.data;
82
+ width = 1 + (((b[2] & 0x3f) << 8) | b[1]);
83
+ height = 1 + (((b[4] & 0xf) << 10) | (b[3] << 2) | ((b[2] & 0xc0) >> 6));
84
+ }
85
+ const flags = Buffer.alloc(4);
86
+ flags[0] = 0x08;
87
+ const dims = Buffer.alloc(6);
88
+ dims.writeUIntLE(width - 1, 0, 3);
89
+ dims.writeUIntLE(height - 1, 3, 3);
90
+ vp8x = { fourCC: 'VP8X', data: Buffer.concat([flags, dims]) };
91
+ }
92
+ else {
93
+ const flagsByte = vp8x.data[0] | 0x08;
94
+ vp8x = { fourCC: 'VP8X', data: Buffer.concat([Buffer.from([flagsByte]), vp8x.data.subarray(1)]) };
95
+ }
96
+ const rebuilt = [vp8x, ...otherChunks, { fourCC: 'EXIF', data: exifData }];
97
+ const chunkBuffers = rebuilt.map(c => buildChunk(c.fourCC, c.data));
98
+ const payload = Buffer.concat(chunkBuffers);
99
+ const riffSize = 4 + payload.length;
100
+ const out = Buffer.alloc(8 + 4 + payload.length);
101
+ out.write('RIFF', 0, 4, 'ascii');
102
+ out.writeUInt32LE(riffSize, 4);
103
+ out.write('WEBP', 8, 4, 'ascii');
104
+ payload.copy(out, 12);
105
+ return out;
106
+ };
107
+ export const makeSticker = async (buffer, { pack = '', author = '', emojis = [], isPrivate = false, animated = false, quality = 60 } = {}) => {
108
+ const webp = await convertToWebp(buffer, { animated, quality });
109
+ return writeExifToWebp(webp, { packName: pack, publisher: author, emojis, isAvatar: isPrivate });
110
+ };
@@ -1,54 +1,49 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.emitSyncActionResults = exports.processContactAction = void 0
4
- const WABinary_1 = require('../WABinary')
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { isLidUser, isPnUser } from '../WABinary/index.js';
5
3
  /**
6
4
  * Process contactAction and return events to emit.
7
5
  * Pure function - no side effects.
8
6
  */
9
- const processContactAction = (action, id, logger) => {
10
- const results = []
11
- if (!id) {
12
- logger?.warn(
13
- { hasFullName: !!action.fullName, hasLidJid: !!action.lidJid, hasPnJid: !!action.pnJid },
14
- 'contactAction sync: missing id in index'
15
- )
16
- return results
17
- }
18
- const lidJid = action.lidJid
19
- const idIsPn = (0, WABinary_1.isPnUser)(id)
20
- // PN is in index[1], not in contactAction.pnJid which is usually null
21
- const phoneNumber = idIsPn ? id : action.pnJid || undefined
22
- // Always emit contacts.upsert
23
- results.push({
24
- event: 'contacts.upsert',
25
- data: [
26
- {
27
- id,
28
- name: action.fullName || action.firstName || action.username || undefined,
29
- username: action.username || undefined,
30
- lid: lidJid || undefined,
31
- phoneNumber
32
- }
33
- ]
34
- })
35
- // Emit lid-mapping.update if we have valid LID-PN pair
36
- if (lidJid && (0, WABinary_1.isLidUser)(lidJid) && idIsPn) {
37
- results.push({
38
- event: 'lid-mapping.update',
39
- data: { lid: lidJid, pn: id }
40
- })
41
- }
42
- return results
43
- }
44
- exports.processContactAction = processContactAction
45
- const emitSyncActionResults = (ev, results) => {
46
- for (const result of results) {
47
- if (result.event === 'contacts.upsert') {
48
- ev.emit('contacts.upsert', result.data)
49
- } else {
50
- ev.emit('lid-mapping.update', result.data)
51
- }
52
- }
53
- }
54
- exports.emitSyncActionResults = emitSyncActionResults
7
+ export const processContactAction = (action, id, logger) => {
8
+ const results = [];
9
+ if (!id) {
10
+ logger?.warn({ hasFullName: !!action.fullName, hasLidJid: !!action.lidJid, hasPnJid: !!action.pnJid }, 'contactAction sync: missing id in index');
11
+ return results;
12
+ }
13
+ const lidJid = action.lidJid;
14
+ const idIsPn = isPnUser(id);
15
+ // PN is in index[1], not in contactAction.pnJid which is usually null
16
+ const phoneNumber = idIsPn ? id : action.pnJid || undefined;
17
+ // Always emit contacts.upsert
18
+ results.push({
19
+ event: 'contacts.upsert',
20
+ data: [
21
+ {
22
+ id,
23
+ name: action.fullName || action.firstName || action.username || undefined,
24
+ username: action.username || undefined,
25
+ lid: lidJid || undefined,
26
+ phoneNumber
27
+ }
28
+ ]
29
+ });
30
+ // Emit lid-mapping.update if we have valid LID-PN pair
31
+ if (lidJid && isLidUser(lidJid) && idIsPn) {
32
+ results.push({
33
+ event: 'lid-mapping.update',
34
+ data: { lid: lidJid, pn: id }
35
+ });
36
+ }
37
+ return results;
38
+ };
39
+ export const emitSyncActionResults = (ev, results) => {
40
+ for (const result of results) {
41
+ if (result.event === 'contacts.upsert') {
42
+ ev.emit('contacts.upsert', result.data);
43
+ }
44
+ else {
45
+ ev.emit('lid-mapping.update', result.data);
46
+ }
47
+ }
48
+ };
49
+ //# sourceMappingURL=sync-action-utils.js.map