@badzz88/baileys 8.5.4 → 8.5.6

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 (269) hide show
  1. package/README.md +2 -2
  2. package/WAProto/fix-imports.js +69 -79
  3. package/WAProto/index.d.ts +15305 -87935
  4. package/WAProto/index.js +41109 -194076
  5. package/engine-requirements.js +15 -8
  6. package/package.json +23 -19
  7. package/src/Defaults/index.js +186 -0
  8. package/src/Signal/Group/ciphertext-message.js +15 -0
  9. package/src/Signal/Group/group-session-builder.js +86 -0
  10. package/src/Signal/Group/group_cipher.js +82 -0
  11. package/src/Signal/Group/index.js +140 -0
  12. package/src/Signal/Group/keyhelper.js +77 -0
  13. package/src/Signal/Group/sender-chain-key.js +29 -0
  14. package/src/Signal/Group/sender-key-distribution-message.js +66 -0
  15. package/src/Signal/Group/sender-key-message.js +69 -0
  16. package/src/Signal/Group/sender-key-name.js +51 -0
  17. package/src/Signal/Group/sender-key-record.js +44 -0
  18. package/src/Signal/Group/sender-key-state.js +87 -0
  19. package/src/Signal/Group/sender-message-key.js +29 -0
  20. package/src/Signal/libsignal.js +455 -0
  21. package/src/Signal/lid-mapping.js +273 -0
  22. package/src/Socket/Client/index.js +31 -0
  23. package/src/Socket/Client/types.js +13 -0
  24. package/src/Socket/Client/websocket.js +61 -0
  25. package/src/Socket/aigroups.js +221 -0
  26. package/src/Socket/business.js +411 -0
  27. package/src/Socket/chats.js +1449 -0
  28. package/src/Socket/communities.js +463 -0
  29. package/src/Socket/graphql.js +523 -0
  30. package/src/Socket/groups.js +516 -0
  31. package/src/Socket/index.js +31 -0
  32. package/src/Socket/interactive-handler.js +527 -0
  33. package/src/Socket/interop.js +339 -0
  34. package/src/Socket/luxu.js +349 -0
  35. package/src/Socket/managed-account.js +98 -0
  36. package/src/Socket/messages-recv.js +2685 -0
  37. package/src/Socket/messages-send.js +2047 -0
  38. package/src/Socket/mex.js +57 -0
  39. package/src/Socket/newsletter.js +455 -0
  40. package/src/Socket/privacy.js +125 -0
  41. package/src/Socket/registration.js +236 -0
  42. package/src/Socket/socket.js +983 -0
  43. package/src/Socket/text-router.js +65 -0
  44. package/src/Socket/username.js +130 -0
  45. package/src/Store/index.js +33 -0
  46. package/src/Store/keyed-db.js +118 -0
  47. package/src/Store/make-cache-manager-store.js +84 -0
  48. package/src/Store/make-in-memory-store.js +551 -0
  49. package/src/Store/make-ordered-dictionary.js +81 -0
  50. package/src/Store/object-repository.js +26 -0
  51. package/src/Types/Auth.js +31 -0
  52. package/src/Types/Bussines.js +2 -0
  53. package/src/Types/Call.js +2 -0
  54. package/src/Types/Chat.js +4 -0
  55. package/src/Types/Contact.js +2 -0
  56. package/src/Types/Events.js +2 -0
  57. package/src/Types/GroupMetadata.js +2 -0
  58. package/src/Types/Label.js +26 -0
  59. package/src/Types/LabelAssociation.js +8 -0
  60. package/src/Types/Message.js +93 -0
  61. package/src/Types/Mex.js +112 -0
  62. package/src/Types/Newsletter.js +109 -0
  63. package/src/Types/Product.js +2 -0
  64. package/src/Types/Signal.js +2 -0
  65. package/src/Types/Socket.js +2 -0
  66. package/src/Types/State.js +62 -0
  67. package/src/Types/USync.js +2 -0
  68. package/src/Types/index.js +56 -0
  69. package/src/Utils/auth-utils.js +254 -0
  70. package/src/Utils/browser-utils.js +112 -0
  71. package/src/Utils/business.js +240 -0
  72. package/src/Utils/chat-utils.js +1230 -0
  73. package/src/Utils/command-loader.d.ts +27 -0
  74. package/src/Utils/command-loader.js +89 -0
  75. package/src/Utils/companion-reg-client-utils.js +40 -0
  76. package/src/Utils/consumer-application.js +105 -0
  77. package/src/Utils/crypto.js +118 -0
  78. package/src/Utils/curve25519-js.js +242 -0
  79. package/src/Utils/decode-wa-message.js +529 -0
  80. package/src/Utils/event-buffer.js +580 -0
  81. package/src/Utils/generics.js +483 -0
  82. package/src/Utils/group-history.js +44 -0
  83. package/src/Utils/history.js +232 -0
  84. package/src/Utils/identity-change-handler.js +52 -0
  85. package/src/Utils/index.js +58 -0
  86. package/src/Utils/jid-display-normalization.js +195 -0
  87. package/src/Utils/link-preview.js +135 -0
  88. package/src/Utils/logger.js +8 -0
  89. package/src/Utils/lt-hash.js +25 -0
  90. package/src/Utils/make-mutex.js +36 -0
  91. package/src/Utils/message-composer.js +471 -0
  92. package/src/Utils/message-retry-manager.js +217 -0
  93. package/src/Utils/messages-media.js +843 -0
  94. package/src/Utils/messages.js +2817 -0
  95. package/src/Utils/meta-ai-msmsg.js +222 -0
  96. package/src/Utils/native-bridge.js +68 -0
  97. package/src/Utils/noise-handler.js +169 -0
  98. package/src/Utils/offline-node-processor.js +34 -0
  99. package/src/Utils/pre-key-manager.js +90 -0
  100. package/src/Utils/process-message.js +950 -0
  101. package/src/Utils/reporting-utils.js +261 -0
  102. package/src/Utils/session-pool.d.ts +14 -0
  103. package/src/Utils/session-pool.js +70 -0
  104. package/src/Utils/signal.js +217 -0
  105. package/src/Utils/stanza-ack.js +30 -0
  106. package/src/Utils/sticker.d.ts +13 -0
  107. package/src/Utils/sticker.js +123 -0
  108. package/src/Utils/sync-action-utils.js +45 -0
  109. package/src/Utils/tc-token-utils.js +158 -0
  110. package/src/Utils/use-multi-file-auth-state.js +111 -0
  111. package/src/Utils/validate-connection.js +209 -0
  112. package/src/Utils/view-once-cache.d.ts +12 -0
  113. package/src/Utils/view-once-cache.js +63 -0
  114. package/src/Utils/voip-rekey.js +22 -0
  115. package/src/WABinary/constants.js +1304 -0
  116. package/src/WABinary/decode.js +342 -0
  117. package/src/WABinary/encode.js +225 -0
  118. package/src/WABinary/generic-utils.js +238 -0
  119. package/src/WABinary/index.js +34 -0
  120. package/src/WABinary/jid-utils.js +351 -0
  121. package/src/WABinary/types.js +2 -0
  122. package/src/WAM/BinaryInfo.js +13 -0
  123. package/src/WAM/constants.js +39484 -0
  124. package/src/WAM/encode.js +149 -0
  125. package/src/WAM/index.js +32 -0
  126. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  127. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
  128. package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
  129. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
  130. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  131. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
  132. package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
  133. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
  134. package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
  135. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  136. package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  137. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  138. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
  139. package/src/WAUSync/Protocols/index.js +40 -0
  140. package/src/WAUSync/USyncQuery.js +126 -0
  141. package/src/WAUSync/USyncUser.js +50 -0
  142. package/src/WAUSync/index.js +32 -0
  143. package/src/antiban.js +4152 -0
  144. package/{lib → src}/index.js +51 -49
  145. package/lib/Defaults/index.js +0 -195
  146. package/lib/Signal/Group/ciphertext-message.js +0 -15
  147. package/lib/Signal/Group/group-session-builder.js +0 -92
  148. package/lib/Signal/Group/group_cipher.js +0 -89
  149. package/lib/Signal/Group/index.js +0 -136
  150. package/lib/Signal/Group/keyhelper.js +0 -73
  151. package/lib/Signal/Group/sender-chain-key.js +0 -32
  152. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  153. package/lib/Signal/Group/sender-key-message.js +0 -69
  154. package/lib/Signal/Group/sender-key-name.js +0 -50
  155. package/lib/Signal/Group/sender-key-record.js +0 -44
  156. package/lib/Signal/Group/sender-key-state.js +0 -97
  157. package/lib/Signal/Group/sender-message-key.js +0 -30
  158. package/lib/Signal/libsignal.js +0 -470
  159. package/lib/Signal/lid-mapping.js +0 -280
  160. package/lib/Socket/Client/index.js +0 -30
  161. package/lib/Socket/Client/types.js +0 -13
  162. package/lib/Socket/Client/websocket.js +0 -62
  163. package/lib/Socket/aigroups.js +0 -240
  164. package/lib/Socket/business.js +0 -414
  165. package/lib/Socket/chats.js +0 -2165
  166. package/lib/Socket/communities.js +0 -545
  167. package/lib/Socket/graphql.js +0 -863
  168. package/lib/Socket/groups.js +0 -685
  169. package/lib/Socket/index.js +0 -41
  170. package/lib/Socket/interactive-handler.js +0 -579
  171. package/lib/Socket/interop.js +0 -430
  172. package/lib/Socket/managed-account.js +0 -214
  173. package/lib/Socket/messages-recv.js +0 -3000
  174. package/lib/Socket/messages-send.js +0 -2155
  175. package/lib/Socket/mex.js +0 -47
  176. package/lib/Socket/newsletter.js +0 -814
  177. package/lib/Socket/privacy.js +0 -261
  178. package/lib/Socket/registration.js +0 -434
  179. package/lib/Socket/socket.js +0 -1074
  180. package/lib/Socket/username.js +0 -160
  181. package/lib/Store/index.js +0 -36
  182. package/lib/Store/make-cache-manager-store.js +0 -90
  183. package/lib/Store/make-in-memory-store.js +0 -488
  184. package/lib/Store/make-ordered-dictionary.js +0 -81
  185. package/lib/Store/object-repository.js +0 -29
  186. package/lib/Types/Auth.js +0 -38
  187. package/lib/Types/Bussines.js +0 -2
  188. package/lib/Types/Call.js +0 -2
  189. package/lib/Types/Chat.js +0 -4
  190. package/lib/Types/Contact.js +0 -2
  191. package/lib/Types/Events.js +0 -2
  192. package/lib/Types/GroupMetadata.js +0 -2
  193. package/lib/Types/Label.js +0 -27
  194. package/lib/Types/LabelAssociation.js +0 -9
  195. package/lib/Types/Message.js +0 -95
  196. package/lib/Types/Newsletter.js +0 -152
  197. package/lib/Types/Product.js +0 -2
  198. package/lib/Types/Signal.js +0 -2
  199. package/lib/Types/Socket.js +0 -2
  200. package/lib/Types/State.js +0 -70
  201. package/lib/Types/USync.js +0 -2
  202. package/lib/Types/index.js +0 -55
  203. package/lib/Utils/auth-utils.js +0 -301
  204. package/lib/Utils/browser-utils.js +0 -114
  205. package/lib/Utils/business.js +0 -243
  206. package/lib/Utils/chat-utils.js +0 -1272
  207. package/lib/Utils/consumer-application.js +0 -107
  208. package/lib/Utils/crypto.js +0 -125
  209. package/lib/Utils/decode-wa-message.js +0 -793
  210. package/lib/Utils/event-buffer.js +0 -583
  211. package/lib/Utils/generics.js +0 -617
  212. package/lib/Utils/group-history.js +0 -51
  213. package/lib/Utils/history.js +0 -244
  214. package/lib/Utils/identity-change-handler.js +0 -52
  215. package/lib/Utils/index.js +0 -53
  216. package/lib/Utils/jid-display-normalization.js +0 -218
  217. package/lib/Utils/link-preview.js +0 -138
  218. package/lib/Utils/logger.js +0 -9
  219. package/lib/Utils/lt-hash.js +0 -6
  220. package/lib/Utils/make-mutex.js +0 -36
  221. package/lib/Utils/message-composer.js +0 -479
  222. package/lib/Utils/message-inspect.js +0 -393
  223. package/lib/Utils/message-retry-manager.js +0 -205
  224. package/lib/Utils/messages-media.js +0 -925
  225. package/lib/Utils/messages.js +0 -2482
  226. package/lib/Utils/meta-ai-msmsg.js +0 -122
  227. package/lib/Utils/noise-handler.js +0 -194
  228. package/lib/Utils/offline-node-processor.js +0 -37
  229. package/lib/Utils/pre-key-manager.js +0 -97
  230. package/lib/Utils/process-message.js +0 -1139
  231. package/lib/Utils/reporting-utils.js +0 -262
  232. package/lib/Utils/signal.js +0 -189
  233. package/lib/Utils/stanza-ack.js +0 -67
  234. package/lib/Utils/sync-action-utils.js +0 -51
  235. package/lib/Utils/tc-token-utils.js +0 -156
  236. package/lib/Utils/use-multi-file-auth-state.js +0 -137
  237. package/lib/Utils/validate-connection.js +0 -259
  238. package/lib/Utils/voip-rekey.js +0 -22
  239. package/lib/WABinary/constants.js +0 -1304
  240. package/lib/WABinary/decode.js +0 -377
  241. package/lib/WABinary/encode.js +0 -58
  242. package/lib/WABinary/generic-utils.js +0 -150
  243. package/lib/WABinary/index.js +0 -33
  244. package/lib/WABinary/jid-utils.js +0 -374
  245. package/lib/WABinary/types.js +0 -2
  246. package/lib/WAM/BinaryInfo.js +0 -13
  247. package/lib/WAM/constants.js +0 -39486
  248. package/lib/WAM/encode.js +0 -142
  249. package/lib/WAM/index.js +0 -31
  250. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
  251. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
  252. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
  253. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
  254. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  255. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
  256. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
  257. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
  258. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
  259. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  260. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
  261. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  262. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  263. package/lib/WAUSync/Protocols/index.js +0 -40
  264. package/lib/WAUSync/USyncBackoff.js +0 -26
  265. package/lib/WAUSync/USyncQuery.js +0 -204
  266. package/lib/WAUSync/USyncUser.js +0 -58
  267. package/lib/WAUSync/index.js +0 -32
  268. package/lib/antiban.js +0 -4391
  269. /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
@@ -1,488 +0,0 @@
1
- 'use strict'
2
-
3
- var __importDefault =
4
- (this && this.__importDefault) ||
5
- function (mod) {
6
- return mod && mod.__esModule ? mod : { default: mod }
7
- }
8
-
9
- Object.defineProperty(exports, '__esModule', { value: true })
10
-
11
- const WAProto_1 = require('../../WAProto')
12
- const Defaults_1 = require('../Defaults')
13
- const LabelAssociation_1 = require('../Types/LabelAssociation')
14
- const Utils_1 = require('../Utils')
15
- const WABinary_1 = require('../WABinary')
16
- const Store_1 = require('./make-ordered-dictionary')
17
- const object_repository_1 = require('./object-repository')
18
-
19
- const waChatKey = pin => ({
20
- key: c =>
21
- (pin ? (c.pinned ? '1' : '0') : '') +
22
- (c.archived ? '0' : '1') +
23
- (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') +
24
- c.id,
25
- compare: (k1, k2) => k2.localeCompare(k1)
26
- })
27
-
28
- const waMessageID = m => m.key.id || ''
29
-
30
- const waLabelAssociationKey = {
31
- key: la =>
32
- la.type === LabelAssociation_1.LabelAssociationType.Chat
33
- ? la.chatId + la.labelId
34
- : la.chatId + la.messageId + la.labelId,
35
- compare: (k1, k2) => k2.localeCompare(k1)
36
- }
37
-
38
- const makeMessagesDictionary = () => Store_1.makeOrderedDictionary(waMessageID)
39
-
40
- const makeInMemoryStore = config => {
41
- const socket = config.socket
42
- const chatKey = config.chatKey || waChatKey(true)
43
- const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
44
- const logger =
45
- config.logger ||
46
- Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({
47
- stream: 'in-mem-store'
48
- })
49
- const KeyedDB = require('@adiwajshing/keyed-db').default
50
- const chats = new KeyedDB(chatKey, c => c.id)
51
- const messages = {}
52
- const contacts = {}
53
- const groupMetadata = {}
54
- const presences = {}
55
- const state = { connection: 'close' }
56
- const labels = new object_repository_1.ObjectRepository()
57
- const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key)
58
- const assertMessageList = jid => {
59
- if (!messages[jid]) {
60
- messages[jid] = makeMessagesDictionary()
61
- }
62
- return messages[jid]
63
- }
64
- const contactsUpsert = newContacts => {
65
- const oldContacts = new Set(Object.keys(contacts))
66
- for (const contact of newContacts) {
67
- oldContacts.delete(contact.id)
68
- contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact)
69
- }
70
- return oldContacts
71
- }
72
- const labelsUpsert = newLabels => {
73
- for (const label of newLabels) {
74
- labels.upsertById(label.id, label)
75
- }
76
- }
77
-
78
- const bind = ev => {
79
- ev.on('connection.update', update => {
80
- Object.assign(state, update)
81
- })
82
- ev.on(
83
- 'messaging-history.set',
84
- ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
85
- if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
86
-
87
- return
88
- }
89
- if (isLatest) {
90
- chats.clear()
91
- for (const id in messages) {
92
- delete messages[id]
93
- }
94
- }
95
- const chatsAdded = chats.insertIfAbsent(...newChats).length
96
- logger.debug({ chatsAdded }, 'synced chats')
97
- const oldContacts = contactsUpsert(newContacts)
98
- if (isLatest) {
99
- for (const jid of oldContacts) {
100
- delete contacts[jid]
101
- }
102
- }
103
- logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts')
104
- for (const msg of newMessages) {
105
- const jid = msg.key.remoteJid
106
- const list = assertMessageList(jid)
107
- list.upsert(msg, 'prepend')
108
- }
109
- logger.debug({ messages: newMessages.length }, 'synced messages')
110
- }
111
- )
112
- ev.on('contacts.upsert', contacts => {
113
- contactsUpsert(contacts)
114
- })
115
- ev.on('contacts.update', async updates => {
116
- for (const update of updates) {
117
- let contact
118
- if (contacts[update.id]) {
119
- contact = contacts[update.id]
120
- } else {
121
- const contactHashes = await Promise.all(
122
- Object.keys(contacts).map(async contactId => {
123
- const { user } = WABinary_1.jidDecode(contactId)
124
- return [
125
- contactId,
126
- (await Utils_1.md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)
127
- ]
128
- })
129
- )
130
- contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || '']
131
- }
132
- if (contact) {
133
- if (update.imgUrl === 'changed') {
134
- contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined
135
- } else if (update.imgUrl === 'removed') {
136
- delete contact.imgUrl
137
- }
138
- } else {
139
- return logger.debug({ update }, 'got update for non-existant contact')
140
- }
141
- Object.assign(contacts[contact.id], contact)
142
- }
143
- })
144
- ev.on('chats.upsert', newChats => {
145
- chats.upsert(...newChats)
146
- })
147
- ev.on('chats.update', updates => {
148
- for (let update of updates) {
149
- const result = chats.update(update.id, chat => {
150
- if (update.unreadCount > 0) {
151
- update = { ...update }
152
- update.unreadCount = (chat.unreadCount || 0) + update.unreadCount
153
- }
154
- Object.assign(chat, update)
155
- })
156
- if (!result) {
157
- logger.debug({ update }, 'got update for non-existant chat')
158
- }
159
- }
160
- })
161
- ev.on('labels.edit', label => {
162
- if (label.deleted) {
163
- return labels.deleteById(label.id)
164
- }
165
-
166
- if (labels.count() < 20) {
167
- return labels.upsertById(label.id, label)
168
- }
169
- logger.error('Labels count exceed')
170
- })
171
- ev.on('labels.association', ({ type, association }) => {
172
- switch (type) {
173
- case 'add':
174
- labelAssociations.upsert(association)
175
- break
176
- case 'remove':
177
- labelAssociations.delete(association)
178
- break
179
- default:
180
- logger.error({ type }, 'unknown label association operation type')
181
- }
182
- })
183
- ev.on('presence.update', ({ id, presences: update }) => {
184
- presences[id] = presences[id] || {}
185
- Object.assign(presences[id], update)
186
- })
187
- ev.on('chats.delete', deletions => {
188
- for (const item of deletions) {
189
- if (chats.get(item)) {
190
- chats.deleteById(item)
191
- }
192
- }
193
- })
194
- ev.on('messages.upsert', ({ messages: newMessages, type }) => {
195
- switch (type) {
196
- case 'append':
197
- case 'notify':
198
- for (const msg of newMessages) {
199
- const jid = WABinary_1.jidNormalizedUser(msg.key.remoteJid)
200
- const list = assertMessageList(jid)
201
- list.upsert(msg, 'append')
202
- if (type === 'notify' && !chats.get(jid)) {
203
- ev.emit('chats.upsert', [
204
- {
205
- id: jid,
206
- conversationTimestamp: Utils_1.toNumber(msg.messageTimestamp),
207
- unreadCount: 1
208
- }
209
- ])
210
- }
211
- }
212
- break
213
- }
214
- })
215
- ev.on('messages.update', updates => {
216
- for (const { update, key } of updates) {
217
- const list = assertMessageList(WABinary_1.jidNormalizedUser(key.remoteJid))
218
- if (update?.status) {
219
- const listStatus = list.get(key.id)?.status
220
- if (listStatus && update?.status <= listStatus) {
221
- logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update')
222
- delete update.status
223
- logger.debug({ update }, 'new update object')
224
- }
225
- }
226
- const result = list.updateAssign(key.id, update)
227
- if (!result) {
228
- logger.debug({ update }, 'got update for non-existent message')
229
- }
230
- }
231
- })
232
- ev.on('messages.delete', item => {
233
- if ('all' in item) {
234
- const list = messages[item.jid]
235
- list?.clear()
236
- } else {
237
- const jid = item.keys[0].remoteJid
238
- const list = messages[jid]
239
- if (list) {
240
- const idSet = new Set(item.keys.map(k => k.id))
241
- list.filter(m => !idSet.has(m.key.id))
242
- }
243
- }
244
- })
245
- ev.on('groups.update', updates => {
246
- for (const update of updates) {
247
- const id = update.id
248
- if (groupMetadata[id]) {
249
- Object.assign(groupMetadata[id], update)
250
- } else {
251
- logger.debug({ update }, 'got update for non-existant group metadata')
252
- }
253
- }
254
- })
255
- ev.on('group-participants.update', ({ id, participants, action }) => {
256
- const metadata = groupMetadata[id]
257
- if (metadata) {
258
- switch (action) {
259
- case 'add':
260
- metadata.participants.push(
261
- ...participants.map(id => ({
262
- id,
263
- isAdmin: false,
264
- isSuperAdmin: false
265
- }))
266
- )
267
- break
268
- case 'demote':
269
- case 'promote':
270
- for (const participant of metadata.participants) {
271
- if (participants.includes(participant.id)) {
272
- participant.isAdmin = action === 'promote'
273
- }
274
- }
275
- break
276
- case 'remove':
277
- metadata.participants = metadata.participants.filter(p => !participants.includes(p.id))
278
- break
279
- }
280
- }
281
- })
282
- ev.on('message-receipt.update', updates => {
283
- for (const { key, receipt } of updates) {
284
- const obj = messages[key.remoteJid]
285
- const msg = obj?.get(key.id)
286
- if (msg) {
287
- Utils_1.updateMessageWithReceipt(msg, receipt)
288
- }
289
- }
290
- })
291
- ev.on('messages.reaction', reactions => {
292
- for (const { key, reaction } of reactions) {
293
- const obj = messages[key.remoteJid]
294
- const msg = obj?.get(key.id)
295
- if (msg) {
296
- Utils_1.updateMessageWithReaction(msg, reaction)
297
- }
298
- }
299
- })
300
- ev.on('settings.update', ({ setting, value }) => {
301
- state.settings = state.settings || {}
302
- state.settings[setting] = value
303
- })
304
- ev.on('labels.reorder', ({ labelIds }) => {
305
- let order = 0
306
- for (const id of labelIds) {
307
- const label = labels.findById(id)
308
- if (label) {
309
- labels.upsertById(id, { ...label, order: order++ })
310
- }
311
- order++
312
- }
313
- })
314
- ev.on('call.scheduled', ({ messageKey, scheduledCall, chatId }) => {
315
- state.scheduledCalls = state.scheduledCalls || {}
316
- state.scheduledCalls[messageKey.id] = { key: messageKey, scheduledCall, chatId }
317
- })
318
- ev.on('call.schedule-cancelled', ({ messageKey, editedCallKey }) => {
319
- if (state.scheduledCalls?.[editedCallKey?.id]) {
320
- delete state.scheduledCalls[editedCallKey.id]
321
- }
322
- })
323
- ev.on('payment.split', ({ messageKey, splitPayment }) => {
324
- const list = assertMessageList(WABinary_1.jidNormalizedUser(messageKey.remoteJid))
325
- const msg = list?.get(messageKey.id)
326
- if (msg) {
327
- msg.splitPayment = splitPayment
328
- }
329
- })
330
- ev.on('message.comment', ({ commentKey, comment, targetKey }) => {
331
- const list = assertMessageList(WABinary_1.jidNormalizedUser(targetKey.remoteJid))
332
- const msg = list?.get(targetKey.id)
333
- if (msg) {
334
- msg.commentCount = (msg.commentCount || 0) + 1
335
- }
336
- })
337
- ev.on('poll.add-option', ({ pollKey, addedOption }) => {
338
- const list = assertMessageList(WABinary_1.jidNormalizedUser(pollKey.remoteJid))
339
- const msg = list?.get(pollKey.id)
340
- if (msg?.message) {
341
- const poll =
342
- msg.message.pollCreationMessage ||
343
- msg.message.pollCreationMessageV3 ||
344
- msg.message.pollCreationMessageV5 ||
345
- msg.message.pollCreationMessageV6
346
- if (poll && addedOption) {
347
- poll.options = [...(poll.options || []), addedOption]
348
- }
349
- }
350
- })
351
- ev.on('chats.lock', ({ id, locked }) => {
352
- const result = chats.update(id, chat => {
353
- chat.locked = locked
354
- })
355
- if (!result) logger.debug({ id }, 'got chats.lock for non-existent chat')
356
- })
357
- ev.on('messaging-history.status', ({ syncType, status }) => {
358
- state.historySyncStatus = state.historySyncStatus || {}
359
- state.historySyncStatus[syncType] = status
360
- })
361
- }
362
- const toJSON = () => ({
363
- chats,
364
- contacts,
365
- messages,
366
- labels,
367
- labelAssociations
368
- })
369
- const fromJSON = json => {
370
- chats.upsert(...json.chats)
371
- labelAssociations.upsert(...(json.labelAssociations || []))
372
- contactsUpsert(Object.values(json.contacts))
373
- labelsUpsert(Object.values(json.labels || {}))
374
- for (const jid in json.messages) {
375
- const list = assertMessageList(jid)
376
- for (const msg of json.messages[jid]) {
377
- list.upsert(WAProto_1.proto.WebMessageInfo.fromObject(msg), 'append')
378
- }
379
- }
380
- }
381
- return {
382
- chats,
383
- contacts,
384
- messages,
385
- groupMetadata,
386
- state,
387
- presences,
388
- labels,
389
- labelAssociations,
390
- bind,
391
-
392
- loadMessages: async (jid, count, cursor) => {
393
- const list = assertMessageList(jid)
394
- const mode = !cursor || 'before' in cursor ? 'before' : 'after'
395
- const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined
396
- const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined
397
- let messages
398
- if (list && mode === 'before' && (!cursorKey || cursorValue)) {
399
- if (cursorValue) {
400
- const msgIdx = list.array.findIndex(m => m.key.id === cursorKey?.id)
401
- messages = list.array.slice(0, msgIdx)
402
- } else {
403
- messages = list.array
404
- }
405
- const diff = count - messages.length
406
- if (diff < 0) {
407
- messages = messages.slice(-count)
408
- }
409
- } else {
410
- messages = []
411
- }
412
- return messages
413
- },
414
-
415
- getLabels: () => {
416
- return labels
417
- },
418
-
419
- getChatLabels: chatId => {
420
- return labelAssociations.filter(la => la.chatId === chatId).all()
421
- },
422
-
423
- getMessageLabels: messageId => {
424
- const associations = labelAssociations.filter(la => la.messageId === messageId).all()
425
- return associations.map(({ labelId }) => labelId)
426
- },
427
- loadMessage: async (jid, id) => messages[jid]?.get(id),
428
- mostRecentMessage: async jid => {
429
- const message = messages[jid]?.array.slice(-1)[0]
430
- return message
431
- },
432
- fetchImageUrl: async (jid, suki) => {
433
- const contact = contacts[jid]
434
- if (!contact) {
435
- return suki?.profilePictureUrl(jid)
436
- }
437
- if (contact.imgUrl === undefined) {
438
- contact.imgUrl = await suki?.profilePictureUrl(jid)
439
- }
440
- return contact.imgUrl
441
- },
442
- fetchGroupMetadata: async (jid, suki) => {
443
- if (!groupMetadata[jid]) {
444
- const metadata = await suki?.groupMetadata(jid)
445
- if (metadata) {
446
- groupMetadata[jid] = metadata
447
- }
448
- }
449
- return groupMetadata[jid]
450
- },
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
- fetchMessageReceipts: async ({ remoteJid, id }) => {
461
- const list = messages[remoteJid]
462
- const msg = list?.get(id)
463
- return msg?.userReceipt
464
- },
465
- toJSON,
466
- fromJSON,
467
- writeToFile: path => {
468
-
469
- const { writeFileSync } = require('fs')
470
- writeFileSync(path, JSON.stringify(toJSON()))
471
- },
472
- readFromFile: path => {
473
-
474
- const { readFileSync, existsSync } = require('fs')
475
- if (existsSync(path)) {
476
- logger.debug({ path }, 'reading from file')
477
- const jsonStr = readFileSync(path, { encoding: 'utf-8' })
478
- const json = JSON.parse(jsonStr)
479
- fromJSON(json)
480
- }
481
- }
482
- }
483
- }
484
-
485
- exports.waChatKey = waChatKey
486
- exports.waMessageID = waMessageID
487
- exports.waLabelAssociationKey = waLabelAssociationKey
488
- exports.makeInMemoryStore = makeInMemoryStore
@@ -1,81 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true })
4
-
5
- function makeOrderedDictionary(idGetter) {
6
- const array = []
7
- const dict = {}
8
- const get = id => dict[id]
9
- const update = item => {
10
- const id = idGetter(item)
11
- const idx = array.findIndex(i => idGetter(i) === id)
12
- if (idx >= 0) {
13
- array[idx] = item
14
- dict[id] = item
15
- }
16
- return false
17
- }
18
- const upsert = (item, mode) => {
19
- const id = idGetter(item)
20
- if (get(id)) {
21
- update(item)
22
- } else {
23
- if (mode === 'append') {
24
- array.push(item)
25
- } else {
26
- array.splice(0, 0, item)
27
- }
28
- dict[id] = item
29
- }
30
- }
31
- const remove = item => {
32
- const id = idGetter(item)
33
- const idx = array.findIndex(i => idGetter(i) === id)
34
- if (idx >= 0) {
35
- array.splice(idx, 1)
36
- delete dict[id]
37
- return true
38
- }
39
- return false
40
- }
41
- return {
42
- array,
43
- get,
44
- upsert,
45
- update,
46
- remove,
47
- updateAssign: (id, update) => {
48
- const item = get(id)
49
- if (item) {
50
- Object.assign(item, update)
51
- delete dict[id]
52
- dict[idGetter(item)] = item
53
- return true
54
- }
55
- return false
56
- },
57
- clear: () => {
58
- array.splice(0, array.length)
59
- for (const key of Object.keys(dict)) {
60
- delete dict[key]
61
- }
62
- },
63
- filter: contain => {
64
- let i = 0
65
- while (i < array.length) {
66
- if (!contain(array[i])) {
67
- delete dict[idGetter(array[i])]
68
- array.splice(i, 1)
69
- } else {
70
- i += 1
71
- }
72
- }
73
- },
74
- toJSON: () => array,
75
- fromJSON: newItems => {
76
- array.splice(0, array.length, ...newItems)
77
- }
78
- }
79
- }
80
-
81
- exports.makeOrderedDictionary = makeOrderedDictionary
@@ -1,29 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true })
4
-
5
- class ObjectRepository {
6
- constructor(entities = {}) {
7
- this.entityMap = new Map(Object.entries(entities))
8
- }
9
- findById(id) {
10
- return this.entityMap.get(id)
11
- }
12
- findAll() {
13
- return Array.from(this.entityMap.values())
14
- }
15
- upsertById(id, entity) {
16
- return this.entityMap.set(id, { ...entity })
17
- }
18
- deleteById(id) {
19
- return this.entityMap.delete(id)
20
- }
21
- count() {
22
- return this.entityMap.size
23
- }
24
- toJSON() {
25
- return this.findAll()
26
- }
27
- }
28
-
29
- exports.ObjectRepository = ObjectRepository
package/lib/Types/Auth.js DELETED
@@ -1,38 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
-
4
-
5
- function createKeyPair(publicKey, privateKey) {
6
- return {
7
- public: publicKey,
8
- private: privateKey
9
- }
10
- }
11
-
12
- function createSignedKeyPair(keyPair, signature, keyId, timestampS) {
13
- return {
14
- keyPair,
15
- signature,
16
- keyId,
17
- timestampS
18
- }
19
- }
20
-
21
-
22
- exports.SignalDataTypeMap = {
23
- 'pre-key': 'KeyPair',
24
- session: 'Uint8Array',
25
- 'sender-key': 'Uint8Array',
26
- 'sender-key-memory': 'object',
27
- 'app-state-sync-key': 'proto.Message.IAppStateSyncKeyData',
28
- 'app-state-sync-version': 'LTHashState',
29
- 'lid-mapping': 'string',
30
- 'device-list': 'Array',
31
- tctoken: 'object'
32
- }
33
- exports.SignalDataSet = undefined
34
- exports.Awaitable = undefined
35
-
36
-
37
- exports.createKeyPair = createKeyPair
38
- exports.createSignedKeyPair = createSignedKeyPair
@@ -1,2 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
package/lib/Types/Call.js DELETED
@@ -1,2 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
package/lib/Types/Chat.js DELETED
@@ -1,4 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.ALL_WA_PATCH_NAMES = void 0
4
- exports.ALL_WA_PATCH_NAMES = ['critical_block', 'critical_unblock_low', 'regular_high', 'regular_low', 'regular']
@@ -1,2 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
@@ -1,2 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
@@ -1,2 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
@@ -1,27 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.LabelColor = void 0
4
-
5
- var LabelColor
6
- ;(function (LabelColor) {
7
- LabelColor[(LabelColor['Color1'] = 0)] = 'Color1'
8
- LabelColor[(LabelColor['Color2'] = 1)] = 'Color2'
9
- LabelColor[(LabelColor['Color3'] = 2)] = 'Color3'
10
- LabelColor[(LabelColor['Color4'] = 3)] = 'Color4'
11
- LabelColor[(LabelColor['Color5'] = 4)] = 'Color5'
12
- LabelColor[(LabelColor['Color6'] = 5)] = 'Color6'
13
- LabelColor[(LabelColor['Color7'] = 6)] = 'Color7'
14
- LabelColor[(LabelColor['Color8'] = 7)] = 'Color8'
15
- LabelColor[(LabelColor['Color9'] = 8)] = 'Color9'
16
- LabelColor[(LabelColor['Color10'] = 9)] = 'Color10'
17
- LabelColor[(LabelColor['Color11'] = 10)] = 'Color11'
18
- LabelColor[(LabelColor['Color12'] = 11)] = 'Color12'
19
- LabelColor[(LabelColor['Color13'] = 12)] = 'Color13'
20
- LabelColor[(LabelColor['Color14'] = 13)] = 'Color14'
21
- LabelColor[(LabelColor['Color15'] = 14)] = 'Color15'
22
- LabelColor[(LabelColor['Color16'] = 15)] = 'Color16'
23
- LabelColor[(LabelColor['Color17'] = 16)] = 'Color17'
24
- LabelColor[(LabelColor['Color18'] = 17)] = 'Color18'
25
- LabelColor[(LabelColor['Color19'] = 18)] = 'Color19'
26
- LabelColor[(LabelColor['Color20'] = 19)] = 'Color20'
27
- })(LabelColor || (exports.LabelColor = LabelColor = {}))
@@ -1,9 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.LabelAssociationType = void 0
4
-
5
- var LabelAssociationType
6
- ;(function (LabelAssociationType) {
7
- LabelAssociationType['Chat'] = 'label_jid'
8
- LabelAssociationType['Message'] = 'label_message'
9
- })(LabelAssociationType || (exports.LabelAssociationType = LabelAssociationType = {}))