@hiroosy/baileys-lite 0.0.4 → 0.3.1
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/LICENSE +21 -0
- package/README.md +658 -10
- package/WAProto/index.js +2 -2558
- package/engine-requirements.js +3 -4
- package/package.json +8 -3
- package/src/binary/wa-binary.js +3 -25
- package/src/constants.js +7 -15
- package/src/defaults.js +2 -5
- package/src/foundation/ai-rich.js +530 -0
- package/src/foundation/audio-duration.js +43 -103
- package/src/foundation/audio-samples.js +19 -37
- package/src/foundation/boom.js +0 -7
- package/src/foundation/cache.js +4 -26
- package/src/foundation/concurrency.js +1 -19
- package/src/foundation/curve25519.js +7 -39
- package/src/foundation/link-preview.js +15 -57
- package/src/foundation/logger.js +0 -11
- package/src/foundation/long.js +4 -14
- package/src/foundation/protobuf-minimal.js +21 -53
- package/src/foundation/qrcode-terminal.js +273 -0
- package/src/foundation/sql-database.js +716 -0
- package/src/foundation/wa-crypto.js +2 -31
- package/src/foundation/zip.js +25 -41
- package/src/index.js +8 -18
- package/src/signal/libsignal.js +23 -78
- package/src/signal/signal-group.js +0 -35
- package/src/signal/signal-repository.js +10 -29
- package/src/socket/business-communities.js +12 -31
- package/src/socket/chats.js +5 -8
- package/src/socket/groups-newsletter.js +18 -17
- package/src/socket/messages-recv.js +81 -127
- package/src/socket/messages-send.js +372 -139
- package/src/socket/socket-core.js +227 -157
- package/src/socket/usync.js +2 -6
- package/src/socket-client/native-websocket.js +344 -0
- package/src/socket-client/websocket-client.js +84 -38
- package/src/utils/auth-state-core.js +14 -56
- package/src/utils/auth-state-storage.js +7 -42
- package/src/utils/chat-sync.js +4 -26
- package/src/utils/media.js +15 -71
- package/src/utils/message-compose.js +208 -85
- package/src/utils/message-processing.js +10 -65
- package/src/utils/username.js +19 -0
- package/src/utils/wa-protocol-core.js +71 -127
- package/src/vendor/jpeg-js/decoder.js +75 -136
- package/src/vendor/jpeg-js/encoder.js +179 -264
- package/src/vendor/pngjs/bitmapper.js +5 -27
- package/src/vendor/pngjs/bitpacker.js +4 -12
- package/src/vendor/pngjs/constants.js +3 -11
- package/src/vendor/pngjs/crc.js +0 -6
- package/src/vendor/pngjs/filter-pack.js +1 -7
- package/src/vendor/pngjs/filter-parse-sync.js +0 -6
- package/src/vendor/pngjs/filter-parse.js +1 -11
- package/src/vendor/pngjs/format-normaliser.js +5 -11
- package/src/vendor/pngjs/interlace.js +7 -24
- package/src/vendor/pngjs/packer-sync.js +0 -11
- package/src/vendor/pngjs/packer.js +7 -15
- package/src/vendor/pngjs/paeth-predictor.js +0 -6
- package/src/vendor/pngjs/parser-sync.js +0 -8
- package/src/vendor/pngjs/parser.js +5 -29
- package/src/vendor/pngjs/png-sync.js +0 -7
- package/src/vendor/pngjs/sync-inflate.js +7 -16
- package/src/vendor/pngjs/sync-reader.js +4 -11
- package/src/voip/WaVoipCoordinator.js +158 -0
- package/src/voip/app-data/WaAppDataStream.js +193 -0
- package/src/voip/app-data/protocol.js +172 -0
- package/src/voip/bytes.js +63 -0
- package/src/voip/call/WaCallManager.js +442 -0
- package/src/voip/call/WaCallMediaSession.js +1705 -0
- package/src/voip/call/call-state.js +203 -0
- package/src/voip/crypto/encryption.js +13 -0
- package/src/voip/crypto/primitives.js +21 -0
- package/src/voip/crypto/rtcp.js +66 -0
- package/src/voip/crypto/srtp.js +180 -0
- package/src/voip/crypto/ssrc.js +15 -0
- package/src/voip/index.js +628 -0
- package/src/voip/media/WaAudioEngine.js +486 -0
- package/src/voip/media/WaVideoEngine.js +275 -0
- package/src/voip/media/audio-codec.js +0 -0
- package/src/voip/media/audio-reorder.js +107 -0
- package/src/voip/media/h264.js +246 -0
- package/src/voip/media/mlow-codec.js +465 -0
- package/src/voip/media/rtcp.js +68 -0
- package/src/voip/media/rtp.js +242 -0
- package/src/voip/protobuf.js +30 -0
- package/src/voip/relay/WaManualRelay.js +609 -0
- package/src/voip/relay/datachannel/pre-negotiated.js +25 -0
- package/src/voip/relay/dtls/aead.js +46 -0
- package/src/voip/relay/dtls/cert-builder.js +102 -0
- package/src/voip/relay/dtls/der.js +98 -0
- package/src/voip/relay/dtls/ecdhe.js +37 -0
- package/src/voip/relay/dtls/handshake-framing.js +100 -0
- package/src/voip/relay/dtls/handshake-messages.js +158 -0
- package/src/voip/relay/dtls/handshake.js +582 -0
- package/src/voip/relay/dtls/prf.js +39 -0
- package/src/voip/relay/dtls/record.js +56 -0
- package/src/voip/relay/relay-ack.js +141 -0
- package/src/voip/relay/sctp/association.js +434 -0
- package/src/voip/relay/sctp/crc32c.js +21 -0
- package/src/voip/relay/sctp/wire.js +226 -0
- package/src/voip/relay/stun.js +463 -0
- package/src/voip/shim/baileys-resolve.js +7 -0
- package/src/voip/shim/core.js +66 -0
- package/src/voip/shim/crypto.js +6 -0
- package/src/voip/shim/proto.js +10 -0
- package/src/voip/shim/protocol.js +130 -0
- package/src/voip/shim/transport.js +82 -0
- package/src/voip/shim/util.js +207 -0
- package/src/voip/signaling/bridge.js +102 -0
- package/src/voip/signaling/screen-share.js +60 -0
- package/src/voip/signaling/signaling.js +491 -0
- package/src/voip/types.js +69 -0
- package/src/voip/voip-deps.js +243 -0
- package/src/voip/voipClient.js +314 -0
- package/src/wam/wam-constants.js +0 -1
- package/src/wam/wam.js +2 -7
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Signal session repository (1:1 E2EE) + LID↔PN identity mapping store.
|
|
3
|
-
* Combines what used to be libsignal.js + lid-mapping.js.
|
|
4
|
-
*
|
|
5
|
-
* The Signal protocol itself (X3DH, Double Ratchet, session state) lives in
|
|
6
|
-
* ./libsignal.js (native port, no npm dependency) — this file is bookkeeping
|
|
7
|
-
* around it (JID <-> protocol address mapping, key storage glue, LID/PN
|
|
8
|
-
* identity resolution), not the crypto itself.
|
|
9
|
-
*/
|
|
10
1
|
import * as libsignal from './libsignal.js'
|
|
11
2
|
import { PreKeyWhisperMessage } from './libsignal.js'
|
|
12
3
|
import { Cache } from '../foundation/cache.js'
|
|
@@ -14,13 +5,9 @@ import { generateSignalPubKey } from '../utils/wa-protocol-core.js'
|
|
|
14
5
|
import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser, transferDevice, WAJIDDomains } from '../binary/wa-binary.js'
|
|
15
6
|
import { SenderKeyName, SenderKeyRecord, GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage } from './signal-group.js'
|
|
16
7
|
|
|
17
|
-
/* ------------------------------------------------------------------ */
|
|
18
|
-
/* LIDMappingStore */
|
|
19
|
-
/* ------------------------------------------------------------------ */
|
|
20
|
-
|
|
21
8
|
export class LIDMappingStore {
|
|
22
9
|
constructor(keys, logger, pnToLIDFunc) {
|
|
23
|
-
this.mappingCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, updateAgeOnGet: true })
|
|
10
|
+
this.mappingCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, max: 10000, updateAgeOnGet: true })
|
|
24
11
|
this.inflightLIDLookups = new Map()
|
|
25
12
|
this.inflightPNLookups = new Map()
|
|
26
13
|
this.keys = keys
|
|
@@ -177,7 +164,7 @@ export class LIDMappingStore {
|
|
|
177
164
|
}
|
|
178
165
|
|
|
179
166
|
if (Object.keys(usyncFetch).length > 0) {
|
|
180
|
-
const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch))
|
|
167
|
+
const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch))
|
|
181
168
|
if (result && result.length > 0) {
|
|
182
169
|
await this.storeLIDPNMappings(result)
|
|
183
170
|
for (const pair of result) {
|
|
@@ -277,16 +264,11 @@ export class LIDMappingStore {
|
|
|
277
264
|
}
|
|
278
265
|
}
|
|
279
266
|
|
|
280
|
-
/* ------------------------------------------------------------------ */
|
|
281
|
-
/* Signal session repository */
|
|
282
|
-
/* ------------------------------------------------------------------ */
|
|
283
|
-
|
|
284
|
-
/** Extract identity key from PreKeyWhisperMessage for identity change detection */
|
|
285
267
|
function extractIdentityFromPkmsg(ciphertext) {
|
|
286
268
|
try {
|
|
287
269
|
if (!ciphertext || ciphertext.length < 2) return undefined
|
|
288
270
|
const version = ciphertext[0]
|
|
289
|
-
if ((version & 0xf) !== 3) return undefined
|
|
271
|
+
if ((version & 0xf) !== 3) return undefined
|
|
290
272
|
const preKeyProto = PreKeyWhisperMessage.decode(ciphertext.slice(1))
|
|
291
273
|
if (preKeyProto.identityKey?.length === 33) return new Uint8Array(preKeyProto.identityKey)
|
|
292
274
|
return undefined
|
|
@@ -299,7 +281,7 @@ export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
|
|
|
299
281
|
const lidMapping = new LIDMappingStore(auth.keys, logger, pnToLIDFunc)
|
|
300
282
|
const storage = signalStorage(auth, lidMapping)
|
|
301
283
|
const parsedKeys = auth.keys
|
|
302
|
-
const migratedSessionCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, updateAgeOnGet: true })
|
|
284
|
+
const migratedSessionCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, updateAgeOnGet: true })
|
|
303
285
|
|
|
304
286
|
const ensureSenderKeyAndCreateSkdm = async (group, meId) => {
|
|
305
287
|
const senderName = jidToSignalSenderKeyName(group, meId)
|
|
@@ -405,8 +387,7 @@ export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
|
|
|
405
387
|
logger.trace({ jid }, 'injecting E2EE session')
|
|
406
388
|
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
|
|
407
389
|
return parsedKeys.transaction(async () => {
|
|
408
|
-
|
|
409
|
-
// but the bundled .d.ts marks it required.
|
|
390
|
+
|
|
410
391
|
await cipher.initOutgoing(session)
|
|
411
392
|
}, jid)
|
|
412
393
|
},
|
|
@@ -447,9 +428,9 @@ export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
|
|
|
447
428
|
},
|
|
448
429
|
|
|
449
430
|
async migrateSession(fromJid, toJid) {
|
|
450
|
-
|
|
431
|
+
|
|
451
432
|
if (!fromJid || (!isLidUser(toJid) && !isHostedLidUser(toJid))) return { migrated: 0, skipped: 0, total: 0 }
|
|
452
|
-
if (!isPnUser(fromJid) && !isHostedPnUser(fromJid)) return { migrated: 0, skipped: 0, total: 1 }
|
|
433
|
+
if (!isPnUser(fromJid) && !isHostedPnUser(fromJid)) return { migrated: 0, skipped: 0, total: 1 }
|
|
453
434
|
|
|
454
435
|
const { user } = jidDecode(fromJid)
|
|
455
436
|
logger.debug({ fromJid }, 'bulk device migration - loading all user devices')
|
|
@@ -550,7 +531,7 @@ const jidToSignalProtocolAddress = jid => {
|
|
|
550
531
|
const jidToSignalSenderKeyName = (group, user) => new SenderKeyName(group, jidToSignalProtocolAddress(user))
|
|
551
532
|
|
|
552
533
|
function signalStorage({ creds, keys }, lidMapping) {
|
|
553
|
-
|
|
534
|
+
|
|
554
535
|
const resolveLIDSignalAddress = async id => {
|
|
555
536
|
if (id.includes('.')) {
|
|
556
537
|
const [deviceId, device] = id.split('.')
|
|
@@ -584,7 +565,7 @@ function signalStorage({ creds, keys }, lidMapping) {
|
|
|
584
565
|
await keys.set({ session: { [wireJid]: session.serialize() } })
|
|
585
566
|
},
|
|
586
567
|
|
|
587
|
-
isTrustedIdentity: () => true,
|
|
568
|
+
isTrustedIdentity: () => true,
|
|
588
569
|
|
|
589
570
|
loadIdentityKey: async id => {
|
|
590
571
|
const wireJid = await resolveLIDSignalAddress(id)
|
|
@@ -601,7 +582,7 @@ function signalStorage({ creds, keys }, lidMapping) {
|
|
|
601
582
|
return true
|
|
602
583
|
}
|
|
603
584
|
if (!existingKey) {
|
|
604
|
-
await keys.set({ 'identity-key': { [wireJid]: identityKey } })
|
|
585
|
+
await keys.set({ 'identity-key': { [wireJid]: identityKey } })
|
|
605
586
|
return true
|
|
606
587
|
}
|
|
607
588
|
return false
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Business + Communities socket layers (the outermost wrappers).
|
|
3
|
-
* Combines Socket/business.js and Socket/communities.js:
|
|
4
|
-
*
|
|
5
|
-
* makeMessagesRecvSocket -> makeBusinessSocket -> makeCommunitiesSocket
|
|
6
|
-
*
|
|
7
|
-
* makeCommunitiesSocket is what index.js exports as makeWASocket.
|
|
8
|
-
* (Catalog parse helpers such as parseCatalogNode live in utils/message-processing.js.)
|
|
9
|
-
*/
|
|
10
1
|
import { proto } from '../../WAProto/index.js'
|
|
11
2
|
import logger from '../foundation/logger.js'
|
|
12
3
|
import { WAMessageStubType } from '../constants.js'
|
|
@@ -323,7 +314,7 @@ export const makeBusinessSocket = (config) => {
|
|
|
323
314
|
return parseProductNode(productNode);
|
|
324
315
|
};
|
|
325
316
|
const productCreate = async (create) => {
|
|
326
|
-
|
|
317
|
+
|
|
327
318
|
create.isHidden = !!create.isHidden;
|
|
328
319
|
create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
|
|
329
320
|
const createNode = toProductNode(undefined, create);
|
|
@@ -586,17 +577,17 @@ export const makeCommunitiesSocket = (config) => {
|
|
|
586
577
|
communityFetchLinkedGroups: async (jid) => {
|
|
587
578
|
let communityJid = jid;
|
|
588
579
|
let isCommunity = false;
|
|
589
|
-
|
|
580
|
+
|
|
590
581
|
const metadata = await sock.groupMetadata(jid);
|
|
591
582
|
if (metadata.linkedParent) {
|
|
592
|
-
|
|
583
|
+
|
|
593
584
|
communityJid = metadata.linkedParent;
|
|
594
585
|
}
|
|
595
586
|
else {
|
|
596
|
-
|
|
587
|
+
|
|
597
588
|
isCommunity = true;
|
|
598
589
|
}
|
|
599
|
-
|
|
590
|
+
|
|
600
591
|
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
|
|
601
592
|
const linkedGroupsData = [];
|
|
602
593
|
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups');
|
|
@@ -699,23 +690,14 @@ export const makeCommunitiesSocket = (config) => {
|
|
|
699
690
|
const result = getBinaryNodeChild(results, 'community');
|
|
700
691
|
return result?.attrs.jid;
|
|
701
692
|
},
|
|
702
|
-
|
|
703
|
-
* revoke a v4 invite for someone
|
|
704
|
-
* @param communityJid community jid
|
|
705
|
-
* @param invitedJid jid of person you invited
|
|
706
|
-
* @returns true if successful
|
|
707
|
-
*/
|
|
693
|
+
|
|
708
694
|
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
709
695
|
const result = await communityQuery(communityJid, 'set', [
|
|
710
696
|
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
711
697
|
]);
|
|
712
698
|
return !!result;
|
|
713
699
|
},
|
|
714
|
-
|
|
715
|
-
* accept a CommunityInviteMessage
|
|
716
|
-
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
717
|
-
* @param inviteMessage the message to accept
|
|
718
|
-
*/
|
|
700
|
+
|
|
719
701
|
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
720
702
|
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
721
703
|
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
@@ -728,10 +710,9 @@ export const makeCommunitiesSocket = (config) => {
|
|
|
728
710
|
}
|
|
729
711
|
}
|
|
730
712
|
]);
|
|
731
|
-
|
|
732
|
-
// update the invite message to be expired
|
|
713
|
+
|
|
733
714
|
if (key.id) {
|
|
734
|
-
|
|
715
|
+
|
|
735
716
|
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
736
717
|
inviteMessage.inviteExpiration = 0;
|
|
737
718
|
inviteMessage.inviteCode = '';
|
|
@@ -746,13 +727,13 @@ export const makeCommunitiesSocket = (config) => {
|
|
|
746
727
|
}
|
|
747
728
|
]);
|
|
748
729
|
}
|
|
749
|
-
|
|
730
|
+
|
|
750
731
|
await upsertMessage({
|
|
751
732
|
key: {
|
|
752
733
|
remoteJid: inviteMessage.groupJid,
|
|
753
734
|
id: generateMessageIDV2(sock.user?.id),
|
|
754
735
|
fromMe: false,
|
|
755
|
-
participant: key.remoteJid
|
|
736
|
+
participant: key.remoteJid
|
|
756
737
|
},
|
|
757
738
|
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
758
739
|
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
@@ -818,7 +799,7 @@ export const extractCommunityMetadata = (result) => {
|
|
|
818
799
|
memberAddMode,
|
|
819
800
|
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
|
|
820
801
|
return {
|
|
821
|
-
|
|
802
|
+
|
|
822
803
|
id: attrs.jid,
|
|
823
804
|
admin: (attrs.type || null)
|
|
824
805
|
};
|
package/src/socket/chats.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chats socket layer (wraps makeSocket). Combines what used to be Socket/chats.js.
|
|
3
|
-
*/
|
|
4
1
|
import { proto } from '../../WAProto/index.js'
|
|
5
2
|
import { Boom } from '../foundation/boom.js'
|
|
6
3
|
import { Cache } from '../foundation/cache.js'
|
|
@@ -48,7 +45,7 @@ export const makeChatsSocket = config => {
|
|
|
48
45
|
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, sendUnifiedSession, registerSocketEndHandler } = sock
|
|
49
46
|
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping)
|
|
50
47
|
let privacySettings
|
|
51
|
-
|
|
48
|
+
|
|
52
49
|
const serverProps = {
|
|
53
50
|
privacyTokenOn1to1: true,
|
|
54
51
|
profilePicPrivacyToken: true,
|
|
@@ -127,7 +124,7 @@ export const makeChatsSocket = config => {
|
|
|
127
124
|
}
|
|
128
125
|
return userId
|
|
129
126
|
}
|
|
130
|
-
|
|
127
|
+
|
|
131
128
|
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
132
129
|
let targetJid
|
|
133
130
|
if (!jid) throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
|
|
@@ -139,7 +136,7 @@ export const makeChatsSocket = config => {
|
|
|
139
136
|
content: [{ tag: 'picture', attrs: { type: 'image' }, content: img }]
|
|
140
137
|
})
|
|
141
138
|
}
|
|
142
|
-
|
|
139
|
+
|
|
143
140
|
const removeProfilePicture = async jid => {
|
|
144
141
|
let targetJid
|
|
145
142
|
if (!jid) throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
|
|
@@ -308,7 +305,7 @@ export const makeChatsSocket = config => {
|
|
|
308
305
|
const { onMutation } = newAppStateChunkHandler(isInitialSync)
|
|
309
306
|
for (const key in globalMutationMap) onMutation(globalMutationMap[key])
|
|
310
307
|
})
|
|
311
|
-
|
|
308
|
+
|
|
312
309
|
const profilePictureUrl = async (jid, type = 'image', timeoutMs = 5000, shouldIncludeTcToken = true) => {
|
|
313
310
|
const normalizedJid = jidNormalizedUser(jid)
|
|
314
311
|
const isUserJid = isPnUser(normalizedJid) || isLidUser(normalizedJid)
|
|
@@ -409,7 +406,7 @@ export const makeChatsSocket = config => {
|
|
|
409
406
|
for (const key in mutationMap) onMutation(mutationMap[key])
|
|
410
407
|
}
|
|
411
408
|
}
|
|
412
|
-
|
|
409
|
+
|
|
413
410
|
const fetchProps = async () => {
|
|
414
411
|
const resultNode = await query({
|
|
415
412
|
tag: 'iq',
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Groups + newsletter socket layers. Combines what used to be Socket/groups.js
|
|
3
|
-
* and Socket/newsletter.js.
|
|
4
|
-
*
|
|
5
|
-
* Wrap order (must match upstream exactly): makeChatsSocket -> makeGroupsSocket
|
|
6
|
-
* -> makeNewsletterSocket. This file's export (makeNewsletterSocket) is what
|
|
7
|
-
* messages-send.js wraps next.
|
|
8
|
-
*/
|
|
9
1
|
import { proto } from '../../WAProto/index.js'
|
|
10
2
|
import { Boom } from '../foundation/boom.js'
|
|
11
3
|
import { WAMessageAddressingMode, WAMessageStubType, QueryIds, XWAPaths } from '../constants.js'
|
|
@@ -15,10 +7,6 @@ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, is
|
|
|
15
7
|
import { executeWMexQuery as genericExecuteWMexQuery } from './socket-core.js'
|
|
16
8
|
import { makeChatsSocket } from './chats.js'
|
|
17
9
|
|
|
18
|
-
/* ------------------------------------------------------------------ */
|
|
19
|
-
/* Groups */
|
|
20
|
-
/* ------------------------------------------------------------------ */
|
|
21
|
-
|
|
22
10
|
export const extractGroupMetadata = result => {
|
|
23
11
|
const group = getBinaryNodeChild(result, 'group')
|
|
24
12
|
if (!group) {
|
|
@@ -217,10 +205,6 @@ export const makeGroupsSocket = config => {
|
|
|
217
205
|
}
|
|
218
206
|
}
|
|
219
207
|
|
|
220
|
-
/* ------------------------------------------------------------------ */
|
|
221
|
-
/* Newsletters (wraps makeGroupsSocket) */
|
|
222
|
-
/* ------------------------------------------------------------------ */
|
|
223
|
-
|
|
224
208
|
const parseNewsletterCreateResponse = response => {
|
|
225
209
|
const { id, thread_metadata: thread, viewer_metadata: viewer } = response
|
|
226
210
|
return {
|
|
@@ -259,7 +243,24 @@ export const makeNewsletterSocket = config => {
|
|
|
259
243
|
return parseNewsletterCreateResponse(rawResponse)
|
|
260
244
|
},
|
|
261
245
|
newsletterUpdate,
|
|
262
|
-
|
|
246
|
+
newsletterFollowers: async (jid, count = 100) => executeWMexQuery({ input: { newsletter_id: jid, count } }, QueryIds.FOLLOWERS, XWAPaths.xwa2_newsletter_followers),
|
|
247
|
+
newsletterSubscribers: async (jid, count = 100) => {
|
|
248
|
+
const response = await executeWMexQuery({ input: { newsletter_id: jid, count } }, QueryIds.FOLLOWERS, XWAPaths.xwa2_newsletter_followers)
|
|
249
|
+
return (response?.followers?.edges ?? []).map(edge => ({
|
|
250
|
+
id: edge?.node?.id,
|
|
251
|
+
phoneNumber: edge?.node?.pn,
|
|
252
|
+
displayName: edge?.node?.display_name,
|
|
253
|
+
username: edge?.node?.username_info?.username,
|
|
254
|
+
role: edge?.role,
|
|
255
|
+
followTime: edge?.follow_time
|
|
256
|
+
}))
|
|
257
|
+
},
|
|
258
|
+
newsletterInsights: async (jid, metrics = ['NET_FOLLOWS', 'UNFOLLOWS']) => executeWMexQuery({ input: { newsletter_id: jid, metrics } }, QueryIds.INSIGHTS, XWAPaths.xwa2_newsletter_admin_insights),
|
|
259
|
+
newsletterAdminInfo: async jid => executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_INFO, XWAPaths.xwa2_newsletter_admin_count),
|
|
260
|
+
newsletterPendingAdminInvites: async jid => {
|
|
261
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.PENDING_ADMIN_INVITES, XWAPaths.xwa2_newsletter_admin_count)
|
|
262
|
+
return (response?.pending_admin_invites ?? []).map(invite => ({ id: invite?.user?.id, phoneNumber: invite?.user?.pn }))
|
|
263
|
+
},
|
|
263
264
|
newsletterSubscribed: async () => executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.xwa2_newsletter_subscribed),
|
|
264
265
|
newsletterMetadata: async (type, key) => {
|
|
265
266
|
const variables = { fetch_creation_time: true, fetch_full_image: true, fetch_viewer_metadata: true, input: { key, type: type.toUpperCase() } }
|