gifted-baileys 1.5.5 → 1.5.7

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 (251) hide show
  1. package/README.md +6 -1642
  2. package/WAProto/WAProto.proto +969 -88
  3. package/WAProto/index.d.ts +13199 -1260
  4. package/WAProto/index.js +124901 -74525
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +284 -0
  7. package/{src → lib}/Defaults/index.js +7 -14
  8. package/lib/Signal/libsignal.d.ts +3 -0
  9. package/lib/Signal/libsignal.js +161 -0
  10. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  11. package/lib/Socket/Client/index.d.ts +2 -0
  12. package/{src → lib}/Socket/Client/index.js +2 -3
  13. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/websocket.d.ts +12 -0
  18. package/lib/Socket/Client/websocket.js +62 -0
  19. package/lib/Socket/business.d.ts +170 -0
  20. package/{src → lib}/Socket/business.js +28 -33
  21. package/lib/Socket/chats.d.ts +81 -0
  22. package/{src → lib}/Socket/chats.js +174 -176
  23. package/lib/Socket/groups.d.ts +115 -0
  24. package/{src → lib}/Socket/groups.js +80 -68
  25. package/lib/Socket/index.d.ts +172 -0
  26. package/{src → lib}/Socket/index.js +4 -1
  27. package/lib/Socket/messages-recv.d.ts +158 -0
  28. package/{src → lib}/Socket/messages-recv.js +378 -211
  29. package/lib/Socket/messages-send.d.ts +155 -0
  30. package/{src → lib}/Socket/messages-send.js +452 -177
  31. package/lib/Socket/newsletter.d.ts +132 -0
  32. package/{src → lib}/Socket/newsletter.js +107 -98
  33. package/lib/Socket/registration.d.ts +264 -0
  34. package/{src → lib}/Socket/registration.js +56 -48
  35. package/lib/Socket/socket.d.ts +44 -0
  36. package/{src → lib}/Socket/socket.js +77 -77
  37. package/lib/Socket/usync.d.ts +37 -0
  38. package/lib/Socket/usync.js +70 -0
  39. package/lib/Store/index.d.ts +3 -0
  40. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  41. package/{src → lib}/Store/make-cache-manager-store.js +25 -34
  42. package/lib/Store/make-in-memory-store.d.ts +118 -0
  43. package/{src → lib}/Store/make-in-memory-store.js +36 -32
  44. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  45. package/lib/Store/object-repository.d.ts +10 -0
  46. package/{src → lib}/Store/object-repository.js +1 -1
  47. package/lib/Types/Auth.d.ts +109 -0
  48. package/lib/Types/Call.d.ts +13 -0
  49. package/lib/Types/Chat.d.ts +107 -0
  50. package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
  51. package/lib/Types/Events.d.ts +172 -0
  52. package/lib/Types/GroupMetadata.d.ts +56 -0
  53. package/lib/Types/Label.d.ts +46 -0
  54. package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
  55. package/lib/Types/Message.d.ts +433 -0
  56. package/lib/Types/Newsletter.d.ts +92 -0
  57. package/lib/Types/Product.d.ts +78 -0
  58. package/lib/Types/Signal.d.ts +57 -0
  59. package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
  60. package/lib/Types/State.d.ts +27 -0
  61. package/lib/Types/USync.d.ts +25 -0
  62. package/lib/Types/index.d.ts +66 -0
  63. package/lib/Utils/auth-utils.d.ts +18 -0
  64. package/{src → lib}/Utils/auth-utils.js +73 -90
  65. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  66. package/lib/Utils/baileys-event-stream.js +63 -0
  67. package/lib/Utils/business.d.ts +22 -0
  68. package/{src → lib}/Utils/business.js +15 -43
  69. package/lib/Utils/chat-utils.d.ts +70 -0
  70. package/{src → lib}/Utils/chat-utils.js +87 -94
  71. package/lib/Utils/crypto.d.ts +40 -0
  72. package/{src → lib}/Utils/crypto.js +4 -2
  73. package/lib/Utils/decode-wa-message.d.ts +36 -0
  74. package/lib/Utils/decode-wa-message.js +226 -0
  75. package/lib/Utils/event-buffer.d.ts +35 -0
  76. package/{src → lib}/Utils/event-buffer.js +4 -13
  77. package/lib/Utils/generics.d.ts +88 -0
  78. package/{src → lib}/Utils/generics.js +67 -86
  79. package/lib/Utils/history.d.ts +19 -0
  80. package/{src → lib}/Utils/history.js +13 -39
  81. package/lib/Utils/index.d.ts +17 -0
  82. package/lib/Utils/link-preview.d.ts +21 -0
  83. package/{src → lib}/Utils/link-preview.js +17 -54
  84. package/lib/Utils/logger.d.ts +2 -0
  85. package/lib/Utils/lt-hash.d.ts +12 -0
  86. package/lib/Utils/make-mutex.d.ts +7 -0
  87. package/{src → lib}/Utils/make-mutex.js +4 -13
  88. package/lib/Utils/messages-media.d.ts +113 -0
  89. package/{src → lib}/Utils/messages-media.js +193 -255
  90. package/lib/Utils/messages.d.ts +77 -0
  91. package/{src → lib}/Utils/messages.js +588 -118
  92. package/lib/Utils/noise-handler.d.ts +20 -0
  93. package/lib/Utils/process-message.d.ts +41 -0
  94. package/{src → lib}/Utils/process-message.js +27 -30
  95. package/lib/Utils/signal.d.ts +33 -0
  96. package/{src → lib}/Utils/signal.js +25 -42
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  98. package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
  99. package/lib/Utils/validate-connection.d.ts +11 -0
  100. package/{src → lib}/Utils/validate-connection.js +40 -9
  101. package/lib/WABinary/constants.d.ts +27 -0
  102. package/lib/WABinary/decode.d.ts +6 -0
  103. package/lib/WABinary/encode.d.ts +2 -0
  104. package/{src → lib}/WABinary/encode.js +16 -10
  105. package/lib/WABinary/generic-utils.d.ts +14 -0
  106. package/lib/WABinary/index.d.ts +5 -0
  107. package/lib/WABinary/jid-utils.d.ts +31 -0
  108. package/lib/WABinary/types.d.ts +18 -0
  109. package/lib/WABinary/types.js +2 -0
  110. package/lib/WAM/BinaryInfo.d.ts +8 -0
  111. package/lib/WAM/constants.d.ts +38 -0
  112. package/lib/WAM/encode.d.ts +2 -0
  113. package/lib/WAM/index.d.ts +3 -0
  114. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  115. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  116. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  117. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  118. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  119. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  120. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  121. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  122. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  123. package/lib/WAUSync/Protocols/index.js +20 -0
  124. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  125. package/lib/WAUSync/USyncQuery.js +79 -0
  126. package/lib/WAUSync/USyncUser.d.ts +10 -0
  127. package/lib/WAUSync/USyncUser.js +22 -0
  128. package/lib/WAUSync/index.d.ts +3 -0
  129. package/lib/WAUSync/index.js +19 -0
  130. package/{src → lib}/index.js +1 -0
  131. package/package.json +26 -8
  132. package/LICENSE +0 -21
  133. package/src/Defaults/baileys-version.json +0 -3
  134. package/src/Defaults/index.ts +0 -131
  135. package/src/Signal/libsignal.js +0 -180
  136. package/src/Signal/libsignal.ts +0 -141
  137. package/src/Socket/Client/abstract-socket-client.ts +0 -19
  138. package/src/Socket/Client/index.ts +0 -3
  139. package/src/Socket/Client/mobile-socket-client.js +0 -78
  140. package/src/Socket/Client/mobile-socket-client.ts +0 -66
  141. package/src/Socket/Client/web-socket-client.js +0 -75
  142. package/src/Socket/Client/web-socket-client.ts +0 -57
  143. package/src/Socket/business.ts +0 -281
  144. package/src/Socket/chats.ts +0 -1030
  145. package/src/Socket/groups.ts +0 -356
  146. package/src/Socket/index.ts +0 -13
  147. package/src/Socket/messages-recv.ts +0 -985
  148. package/src/Socket/messages-send.ts +0 -871
  149. package/src/Socket/newsletter.ts +0 -282
  150. package/src/Socket/registration.ts +0 -250
  151. package/src/Socket/socket.ts +0 -777
  152. package/src/Store/index.ts +0 -3
  153. package/src/Store/make-cache-manager-store.ts +0 -100
  154. package/src/Store/make-in-memory-store.ts +0 -475
  155. package/src/Store/make-ordered-dictionary.ts +0 -86
  156. package/src/Store/object-repository.ts +0 -32
  157. package/src/Tests/test.app-state-sync.js +0 -204
  158. package/src/Tests/test.app-state-sync.ts +0 -207
  159. package/src/Tests/test.event-buffer.js +0 -270
  160. package/src/Tests/test.event-buffer.ts +0 -319
  161. package/src/Tests/test.key-store.js +0 -76
  162. package/src/Tests/test.key-store.ts +0 -92
  163. package/src/Tests/test.libsignal.js +0 -141
  164. package/src/Tests/test.libsignal.ts +0 -186
  165. package/src/Tests/test.media-download.js +0 -93
  166. package/src/Tests/test.media-download.ts +0 -76
  167. package/src/Tests/test.messages.js +0 -33
  168. package/src/Tests/test.messages.ts +0 -37
  169. package/src/Tests/utils.js +0 -34
  170. package/src/Tests/utils.ts +0 -36
  171. package/src/Types/Auth.ts +0 -113
  172. package/src/Types/Call.ts +0 -15
  173. package/src/Types/Chat.ts +0 -106
  174. package/src/Types/Events.ts +0 -93
  175. package/src/Types/GroupMetadata.ts +0 -53
  176. package/src/Types/Label.ts +0 -36
  177. package/src/Types/Message.ts +0 -288
  178. package/src/Types/Newsletter.ts +0 -98
  179. package/src/Types/Product.ts +0 -85
  180. package/src/Types/Signal.ts +0 -68
  181. package/src/Types/State.ts +0 -29
  182. package/src/Types/index.ts +0 -59
  183. package/src/Utils/auth-utils.ts +0 -222
  184. package/src/Utils/baileys-event-stream.js +0 -92
  185. package/src/Utils/baileys-event-stream.ts +0 -66
  186. package/src/Utils/business.ts +0 -275
  187. package/src/Utils/chat-utils.ts +0 -860
  188. package/src/Utils/crypto.ts +0 -131
  189. package/src/Utils/decode-wa-message.js +0 -211
  190. package/src/Utils/decode-wa-message.ts +0 -228
  191. package/src/Utils/event-buffer.ts +0 -613
  192. package/src/Utils/generics.ts +0 -434
  193. package/src/Utils/history.ts +0 -112
  194. package/src/Utils/index.ts +0 -17
  195. package/src/Utils/link-preview.ts +0 -122
  196. package/src/Utils/logger.ts +0 -3
  197. package/src/Utils/lt-hash.ts +0 -61
  198. package/src/Utils/make-mutex.ts +0 -44
  199. package/src/Utils/messages-media.ts +0 -847
  200. package/src/Utils/messages.ts +0 -956
  201. package/src/Utils/noise-handler.ts +0 -197
  202. package/src/Utils/process-message.ts +0 -414
  203. package/src/Utils/signal.ts +0 -177
  204. package/src/Utils/use-multi-file-auth-state.ts +0 -90
  205. package/src/Utils/validate-connection.ts +0 -238
  206. package/src/WABinary/constants.ts +0 -42
  207. package/src/WABinary/decode.ts +0 -265
  208. package/src/WABinary/encode.ts +0 -236
  209. package/src/WABinary/generic-utils.ts +0 -121
  210. package/src/WABinary/index.ts +0 -5
  211. package/src/WABinary/jid-utils.ts +0 -68
  212. package/src/WABinary/types.ts +0 -17
  213. package/src/WAM/BinaryInfo.ts +0 -12
  214. package/src/WAM/constants.ts +0 -15382
  215. package/src/WAM/encode.ts +0 -174
  216. package/src/WAM/index.ts +0 -3
  217. package/src/gifted +0 -1
  218. package/src/index.ts +0 -13
  219. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
  220. /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
  221. /package/{src → lib}/Store/index.js +0 -0
  222. /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
  223. /package/{src → lib}/Types/Auth.js +0 -0
  224. /package/{src → lib}/Types/Call.js +0 -0
  225. /package/{src → lib}/Types/Chat.js +0 -0
  226. /package/{src → lib}/Types/Contact.js +0 -0
  227. /package/{src → lib}/Types/Events.js +0 -0
  228. /package/{src → lib}/Types/GroupMetadata.js +0 -0
  229. /package/{src → lib}/Types/Label.js +0 -0
  230. /package/{src → lib}/Types/LabelAssociation.js +0 -0
  231. /package/{src → lib}/Types/Message.js +0 -0
  232. /package/{src → lib}/Types/Newsletter.js +0 -0
  233. /package/{src → lib}/Types/Product.js +0 -0
  234. /package/{src → lib}/Types/Signal.js +0 -0
  235. /package/{src → lib}/Types/Socket.js +0 -0
  236. /package/{src → lib}/Types/State.js +0 -0
  237. /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
  238. /package/{src → lib}/Types/index.js +0 -0
  239. /package/{src → lib}/Utils/index.js +0 -0
  240. /package/{src → lib}/Utils/logger.js +0 -0
  241. /package/{src → lib}/Utils/lt-hash.js +0 -0
  242. /package/{src → lib}/Utils/noise-handler.js +0 -0
  243. /package/{src → lib}/WABinary/constants.js +0 -0
  244. /package/{src → lib}/WABinary/decode.js +0 -0
  245. /package/{src → lib}/WABinary/generic-utils.js +0 -0
  246. /package/{src → lib}/WABinary/index.js +0 -0
  247. /package/{src → lib}/WABinary/jid-utils.js +0 -0
  248. /package/{src → lib}/WAM/BinaryInfo.js +0 -0
  249. /package/{src → lib}/WAM/constants.js +0 -0
  250. /package/{src → lib}/WAM/encode.js +0 -0
  251. /package/{src → lib}/WAM/index.js +0 -0
@@ -0,0 +1,118 @@
1
+ import type KeyedDB from '@adiwajshing/keyed-db';
2
+ import type { Comparable } from '@adiwajshing/keyed-db/lib/Types';
3
+ import type { Logger } from 'pino';
4
+ import { proto } from '../../WAProto';
5
+ import type makeMDSocket from '../Socket';
6
+ import type { BaileysEventEmitter, Chat, ConnectionState, Contact, GroupMetadata, PresenceData, WAMessage, WAMessageCursor, WAMessageKey } from '../Types';
7
+ import { Label } from '../Types/Label';
8
+ import { LabelAssociation } from '../Types/LabelAssociation';
9
+ import { ObjectRepository } from './object-repository';
10
+ type WASocket = ReturnType<typeof makeMDSocket>;
11
+ export declare const waChatKey: (pin: boolean) => {
12
+ key: (c: Chat) => string;
13
+ compare: (k1: string, k2: string) => number;
14
+ };
15
+ export declare const waMessageID: (m: WAMessage) => string;
16
+ export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>;
17
+ export type BaileysInMemoryStoreConfig = {
18
+ chatKey?: Comparable<Chat, string>;
19
+ labelAssociationKey?: Comparable<LabelAssociation, string>;
20
+ logger?: Logger;
21
+ socket?: WASocket;
22
+ };
23
+ declare const _default: (config: BaileysInMemoryStoreConfig) => {
24
+ chats: KeyedDB<Chat, string>;
25
+ contacts: {
26
+ [_: string]: Contact;
27
+ };
28
+ messages: {
29
+ [_: string]: {
30
+ array: proto.IWebMessageInfo[];
31
+ get: (id: string) => proto.IWebMessageInfo | undefined;
32
+ upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
33
+ update: (item: proto.IWebMessageInfo) => boolean;
34
+ remove: (item: proto.IWebMessageInfo) => boolean;
35
+ updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
36
+ clear: () => void;
37
+ filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
38
+ toJSON: () => proto.IWebMessageInfo[];
39
+ fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
40
+ };
41
+ };
42
+ groupMetadata: {
43
+ [_: string]: GroupMetadata;
44
+ };
45
+ state: ConnectionState;
46
+ presences: {
47
+ [id: string]: {
48
+ [participant: string]: PresenceData;
49
+ };
50
+ };
51
+ labels: ObjectRepository<Label>;
52
+ labelAssociations: KeyedDB<LabelAssociation, string>;
53
+ bind: (ev: BaileysEventEmitter) => void;
54
+ /** loads messages from the store, if not found -- uses the legacy connection */
55
+ loadMessages: (jid: string, count: number, cursor: WAMessageCursor) => Promise<proto.IWebMessageInfo[]>;
56
+ /**
57
+ * Get all available labels for profile
58
+ *
59
+ * Keep in mind that the list is formed from predefined tags and tags
60
+ * that were "caught" during their editing.
61
+ */
62
+ getLabels: () => ObjectRepository<Label>;
63
+ /**
64
+ * Get labels for chat
65
+ *
66
+ * @returns Label IDs
67
+ **/
68
+ getChatLabels: (chatId: string) => LabelAssociation[];
69
+ /**
70
+ * Get labels for message
71
+ *
72
+ * @returns Label IDs
73
+ **/
74
+ getMessageLabels: (messageId: string) => string[];
75
+ loadMessage: (jid: string, id: string) => Promise<proto.IWebMessageInfo | undefined>;
76
+ mostRecentMessage: (jid: string) => Promise<proto.IWebMessageInfo>;
77
+ fetchImageUrl: (jid: string, sock: WASocket | undefined) => Promise<string | null | undefined>;
78
+ fetchGroupMetadata: (jid: string, sock: WASocket | undefined) => Promise<GroupMetadata>;
79
+ fetchMessageReceipts: ({ remoteJid, id }: WAMessageKey) => Promise<proto.IUserReceipt[] | null | undefined>;
80
+ toJSON: () => {
81
+ chats: KeyedDB<Chat, string>;
82
+ contacts: {
83
+ [_: string]: Contact;
84
+ };
85
+ messages: {
86
+ [_: string]: {
87
+ array: proto.IWebMessageInfo[];
88
+ get: (id: string) => proto.IWebMessageInfo | undefined;
89
+ upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
90
+ update: (item: proto.IWebMessageInfo) => boolean;
91
+ remove: (item: proto.IWebMessageInfo) => boolean;
92
+ updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
93
+ clear: () => void;
94
+ filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
95
+ toJSON: () => proto.IWebMessageInfo[];
96
+ fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
97
+ };
98
+ };
99
+ labels: ObjectRepository<Label>;
100
+ labelAssociations: KeyedDB<LabelAssociation, string>;
101
+ };
102
+ fromJSON: (json: {
103
+ chats: Chat[];
104
+ contacts: {
105
+ [id: string]: Contact;
106
+ };
107
+ messages: {
108
+ [id: string]: proto.IWebMessageInfo[];
109
+ };
110
+ labels: {
111
+ [labelId: string]: Label;
112
+ };
113
+ labelAssociations: LabelAssociation[];
114
+ }) => void;
115
+ writeToFile: (path: string) => void;
116
+ readFromFile: (path: string) => void;
117
+ };
118
+ export default _default;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -65,6 +56,14 @@ exports.default = (config) => {
65
56
  labels.upsertById(label.id, label);
66
57
  }
67
58
  };
59
+ const getValidContacts = () => {
60
+ for (const contact of Object.keys(contacts)) {
61
+ if (contact.indexOf('@') < 0) {
62
+ delete contacts[contact];
63
+ }
64
+ }
65
+ return Object.keys(contacts);
66
+ };
68
67
  /**
69
68
  * binds to a BaileysEventEmitter.
70
69
  * It listens to all events and constructs a state that you can query accurate data from.
@@ -75,7 +74,11 @@ exports.default = (config) => {
75
74
  ev.on('connection.update', update => {
76
75
  Object.assign(state, update);
77
76
  });
78
- ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
77
+ ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
78
+ if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
79
+ return; // FOR NOW,
80
+ //TODO: HANDLE
81
+ }
79
82
  if (isLatest) {
80
83
  chats.clear();
81
84
  for (const id in messages) {
@@ -101,7 +104,7 @@ exports.default = (config) => {
101
104
  ev.on('contacts.upsert', contacts => {
102
105
  contactsUpsert(contacts);
103
106
  });
104
- ev.on('contacts.update', (updates) => __awaiter(void 0, void 0, void 0, function* () {
107
+ ev.on('contacts.update', async (updates) => {
105
108
  var _a;
106
109
  for (const update of updates) {
107
110
  let contact;
@@ -109,26 +112,27 @@ exports.default = (config) => {
109
112
  contact = contacts[update.id];
110
113
  }
111
114
  else {
112
- const contactHashes = yield Promise.all(Object.keys(contacts).map((contactId) => __awaiter(void 0, void 0, void 0, function* () {
115
+ const validContacts = getValidContacts();
116
+ const contactHashes = validContacts.map((contactId) => {
113
117
  const { user } = (0, WABinary_1.jidDecode)(contactId);
114
- return [contactId, (yield (0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
115
- })));
118
+ return [contactId, ((0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
119
+ });
116
120
  contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
117
121
  }
118
122
  if (contact) {
119
123
  if (update.imgUrl === 'changed') {
120
- contact.imgUrl = socket ? yield (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
124
+ contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
121
125
  }
122
126
  else if (update.imgUrl === 'removed') {
123
127
  delete contact.imgUrl;
124
128
  }
129
+ Object.assign(contacts[contact.id], contact);
125
130
  }
126
131
  else {
127
- return logger.debug({ update }, 'got update for non-existant contact');
132
+ logger.debug({ update }, 'got update for non-existant contact');
128
133
  }
129
- Object.assign(contacts[contact.id], contact);
130
134
  }
131
- }));
135
+ });
132
136
  ev.on('chats.upsert', newChats => {
133
137
  chats.upsert(...newChats);
134
138
  });
@@ -136,7 +140,7 @@ exports.default = (config) => {
136
140
  for (let update of updates) {
137
141
  const result = chats.update(update.id, chat => {
138
142
  if (update.unreadCount > 0) {
139
- update = Object.assign({}, update);
143
+ update = { ...update };
140
144
  update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
141
145
  }
142
146
  Object.assign(chat, update);
@@ -315,7 +319,7 @@ exports.default = (config) => {
315
319
  labelAssociations,
316
320
  bind,
317
321
  /** loads messages from the store, if not found -- uses the legacy connection */
318
- loadMessages: (jid, count, cursor) => __awaiter(void 0, void 0, void 0, function* () {
322
+ loadMessages: async (jid, count, cursor) => {
319
323
  const list = assertMessageList(jid);
320
324
  const mode = !cursor || 'before' in cursor ? 'before' : 'after';
321
325
  const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
@@ -338,7 +342,7 @@ exports.default = (config) => {
338
342
  messages = [];
339
343
  }
340
344
  return messages;
341
- }),
345
+ },
342
346
  /**
343
347
  * Get all available labels for profile
344
348
  *
@@ -367,31 +371,31 @@ exports.default = (config) => {
367
371
  .all();
368
372
  return associations.map(({ labelId }) => labelId);
369
373
  },
370
- loadMessage: (jid, id) => __awaiter(void 0, void 0, void 0, function* () { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); }),
371
- mostRecentMessage: (jid) => __awaiter(void 0, void 0, void 0, function* () {
374
+ loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
375
+ mostRecentMessage: async (jid) => {
372
376
  var _a;
373
377
  const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
374
378
  return message;
375
- }),
376
- fetchImageUrl: (jid, sock) => __awaiter(void 0, void 0, void 0, function* () {
379
+ },
380
+ fetchImageUrl: async (jid, sock) => {
377
381
  const contact = contacts[jid];
378
382
  if (!contact) {
379
383
  return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
380
384
  }
381
385
  if (typeof contact.imgUrl === 'undefined') {
382
- contact.imgUrl = yield (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
386
+ contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
383
387
  }
384
388
  return contact.imgUrl;
385
- }),
386
- fetchGroupMetadata: (jid, sock) => __awaiter(void 0, void 0, void 0, function* () {
389
+ },
390
+ fetchGroupMetadata: async (jid, sock) => {
387
391
  if (!groupMetadata[jid]) {
388
- const metadata = yield (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
392
+ const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
389
393
  if (metadata) {
390
394
  groupMetadata[jid] = metadata;
391
395
  }
392
396
  }
393
397
  return groupMetadata[jid];
394
- }),
398
+ },
395
399
  // fetchBroadcastListInfo: async(jid: string, sock: WASocket | undefined) => {
396
400
  // if(!groupMetadata[jid]) {
397
401
  // const metadata = await sock?.getBroadcastListInfo(jid)
@@ -401,11 +405,11 @@ exports.default = (config) => {
401
405
  // }
402
406
  // return groupMetadata[jid]
403
407
  // },
404
- fetchMessageReceipts: (_a) => __awaiter(void 0, [_a], void 0, function* ({ remoteJid, id }) {
408
+ fetchMessageReceipts: async ({ remoteJid, id }) => {
405
409
  const list = messages[remoteJid];
406
410
  const msg = list === null || list === void 0 ? void 0 : list.get(id);
407
411
  return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
408
- }),
412
+ },
409
413
  toJSON,
410
414
  fromJSON,
411
415
  writeToFile: (path) => {
@@ -0,0 +1,13 @@
1
+ declare function makeOrderedDictionary<T>(idGetter: (item: T) => string): {
2
+ array: T[];
3
+ get: (id: string) => T | undefined;
4
+ upsert: (item: T, mode: "append" | "prepend") => void;
5
+ update: (item: T) => boolean;
6
+ remove: (item: T) => boolean;
7
+ updateAssign: (id: string, update: Partial<T>) => boolean;
8
+ clear: () => void;
9
+ filter: (contain: (item: T) => boolean) => void;
10
+ toJSON: () => T[];
11
+ fromJSON: (newItems: T[]) => void;
12
+ };
13
+ export default makeOrderedDictionary;
@@ -0,0 +1,10 @@
1
+ export declare class ObjectRepository<T extends object> {
2
+ readonly entityMap: Map<string, T>;
3
+ constructor(entities?: Record<string, T>);
4
+ findById(id: string): T | undefined;
5
+ findAll(): T[];
6
+ upsertById(id: string, entity: T): Map<string, T>;
7
+ deleteById(id: string): boolean;
8
+ count(): number;
9
+ toJSON(): T[];
10
+ }
@@ -12,7 +12,7 @@ class ObjectRepository {
12
12
  return Array.from(this.entityMap.values());
13
13
  }
14
14
  upsertById(id, entity) {
15
- return this.entityMap.set(id, Object.assign({}, entity));
15
+ return this.entityMap.set(id, { ...entity });
16
16
  }
17
17
  deleteById(id) {
18
18
  return this.entityMap.delete(id);
@@ -0,0 +1,109 @@
1
+ import type { proto } from '../../WAProto';
2
+ import { RegistrationOptions } from '../Socket/registration';
3
+ import type { Contact } from './Contact';
4
+ import type { MinimalMessage } from './Message';
5
+ export type KeyPair = {
6
+ public: Uint8Array;
7
+ private: Uint8Array;
8
+ };
9
+ export type SignedKeyPair = {
10
+ keyPair: KeyPair;
11
+ signature: Uint8Array;
12
+ keyId: number;
13
+ timestampS?: number;
14
+ };
15
+ export type ProtocolAddress = {
16
+ name: string;
17
+ deviceId: number;
18
+ };
19
+ export type SignalIdentity = {
20
+ identifier: ProtocolAddress;
21
+ identifierKey: Uint8Array;
22
+ };
23
+ export type LTHashState = {
24
+ version: number;
25
+ hash: Buffer;
26
+ indexValueMap: {
27
+ [indexMacBase64: string]: {
28
+ valueMac: Uint8Array | Buffer;
29
+ };
30
+ };
31
+ };
32
+ export type SignalCreds = {
33
+ readonly signedIdentityKey: KeyPair;
34
+ readonly signedPreKey: SignedKeyPair;
35
+ readonly registrationId: number;
36
+ };
37
+ export type AccountSettings = {
38
+ /** unarchive chats when a new message is received */
39
+ unarchiveChats: boolean;
40
+ /** the default mode to start new conversations with */
41
+ defaultDisappearingMode?: Pick<proto.IConversation, 'ephemeralExpiration' | 'ephemeralSettingTimestamp'>;
42
+ };
43
+ export type AuthenticationCreds = SignalCreds & {
44
+ readonly noiseKey: KeyPair;
45
+ readonly pairingEphemeralKeyPair: KeyPair;
46
+ advSecretKey: string;
47
+ me?: Contact;
48
+ account?: proto.IADVSignedDeviceIdentity;
49
+ signalIdentities?: SignalIdentity[];
50
+ myAppStateKeyId?: string;
51
+ firstUnuploadedPreKeyId: number;
52
+ nextPreKeyId: number;
53
+ lastAccountSyncTimestamp?: number;
54
+ platform?: string;
55
+ processedHistoryMessages: MinimalMessage[];
56
+ /** number of times history & app state has been synced */
57
+ accountSyncCounter: number;
58
+ accountSettings: AccountSettings;
59
+ deviceId: string;
60
+ phoneId: string;
61
+ identityId: Buffer;
62
+ registered: boolean;
63
+ backupToken: Buffer;
64
+ registration: RegistrationOptions;
65
+ pairingCode: string | undefined;
66
+ lastPropHash: string | undefined;
67
+ routingInfo: Buffer | undefined;
68
+ };
69
+ export type SignalDataTypeMap = {
70
+ 'pre-key': KeyPair;
71
+ 'session': Uint8Array;
72
+ 'sender-key': Uint8Array;
73
+ 'sender-key-memory': {
74
+ [jid: string]: boolean;
75
+ };
76
+ 'app-state-sync-key': proto.Message.IAppStateSyncKeyData;
77
+ 'app-state-sync-version': LTHashState;
78
+ };
79
+ export type SignalDataSet = {
80
+ [T in keyof SignalDataTypeMap]?: {
81
+ [id: string]: SignalDataTypeMap[T] | null;
82
+ };
83
+ };
84
+ type Awaitable<T> = T | Promise<T>;
85
+ export type SignalKeyStore = {
86
+ get<T extends keyof SignalDataTypeMap>(type: T, ids: string[]): Awaitable<{
87
+ [id: string]: SignalDataTypeMap[T];
88
+ }>;
89
+ set(data: SignalDataSet): Awaitable<void>;
90
+ /** clear all the data in the store */
91
+ clear?(): Awaitable<void>;
92
+ };
93
+ export type SignalKeyStoreWithTransaction = SignalKeyStore & {
94
+ isInTransaction: () => boolean;
95
+ transaction<T>(exec: () => Promise<T>): Promise<T>;
96
+ };
97
+ export type TransactionCapabilityOptions = {
98
+ maxCommitRetries: number;
99
+ delayBetweenTriesMs: number;
100
+ };
101
+ export type SignalAuthState = {
102
+ creds: SignalCreds;
103
+ keys: SignalKeyStore | SignalKeyStoreWithTransaction;
104
+ };
105
+ export type AuthenticationState = {
106
+ creds: AuthenticationCreds;
107
+ keys: SignalKeyStore;
108
+ };
109
+ export {};
@@ -0,0 +1,13 @@
1
+ export type WACallUpdateType = 'offer' | 'ringing' | 'timeout' | 'reject' | 'accept' | 'terminate';
2
+ export type WACallEvent = {
3
+ chatId: string;
4
+ from: string;
5
+ isGroup?: boolean;
6
+ groupJid?: string;
7
+ id: string;
8
+ date: Date;
9
+ isVideo?: boolean;
10
+ status: WACallUpdateType;
11
+ offline: boolean;
12
+ latencyMs?: number;
13
+ };
@@ -0,0 +1,107 @@
1
+ import type { proto } from '../../WAProto';
2
+ import type { AccountSettings } from './Auth';
3
+ import type { BufferedEventData } from './Events';
4
+ import type { LabelActionBody } from './Label';
5
+ import type { ChatLabelAssociationActionBody } from './LabelAssociation';
6
+ import type { MessageLabelAssociationActionBody } from './LabelAssociation';
7
+ import type { MinimalMessage, WAMessageKey } from './Message';
8
+ /** privacy settings in WhatsApp Web */
9
+ export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
10
+ export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
11
+ export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
12
+ export type WAReadReceiptsValue = 'all' | 'none';
13
+ export type WAPrivacyCallValue = 'all' | 'known';
14
+ /** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
15
+ export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
16
+ export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
17
+ export type WAPatchName = typeof ALL_WA_PATCH_NAMES[number];
18
+ export interface PresenceData {
19
+ lastKnownPresence: WAPresence;
20
+ lastSeen?: number;
21
+ }
22
+ export type ChatMutation = {
23
+ syncAction: proto.ISyncActionData;
24
+ index: string[];
25
+ };
26
+ export type WAPatchCreate = {
27
+ syncAction: proto.ISyncActionValue;
28
+ index: string[];
29
+ type: WAPatchName;
30
+ apiVersion: number;
31
+ operation: proto.SyncdMutation.SyncdOperation;
32
+ };
33
+ export type Chat = proto.IConversation & {
34
+ /** unix timestamp of when the last message was received in the chat */
35
+ lastMessageRecvTimestamp?: number;
36
+ };
37
+ export type ChatUpdate = Partial<Chat & {
38
+ /**
39
+ * if specified in the update,
40
+ * the EV buffer will check if the condition gets fulfilled before applying the update
41
+ * Right now, used to determine when to release an app state sync event
42
+ *
43
+ * @returns true, if the update should be applied;
44
+ * false if it can be discarded;
45
+ * undefined if the condition is not yet fulfilled
46
+ * */
47
+ conditional: (bufferedData: BufferedEventData) => boolean | undefined;
48
+ }>;
49
+ /**
50
+ * the last messages in a chat, sorted reverse-chronologically. That is, the latest message should be first in the chat
51
+ * for MD modifications, the last message in the array (i.e. the earlist message) must be the last message recv in the chat
52
+ * */
53
+ export type LastMessageList = MinimalMessage[] | proto.SyncActionValue.ISyncActionMessageRange;
54
+ export type ChatModification = {
55
+ archive: boolean;
56
+ lastMessages: LastMessageList;
57
+ } | {
58
+ pushNameSetting: string;
59
+ } | {
60
+ pin: boolean;
61
+ } | {
62
+ /** mute for duration, or provide timestamp of mute to remove*/
63
+ mute: number | null;
64
+ } | {
65
+ clear: boolean;
66
+ } | {
67
+ deleteForMe: {
68
+ deleteMedia: boolean;
69
+ key: WAMessageKey;
70
+ timestamp: number;
71
+ };
72
+ } | {
73
+ star: {
74
+ messages: {
75
+ id: string;
76
+ fromMe?: boolean;
77
+ }[];
78
+ star: boolean;
79
+ };
80
+ } | {
81
+ markRead: boolean;
82
+ lastMessages: LastMessageList;
83
+ } | {
84
+ delete: true;
85
+ lastMessages: LastMessageList;
86
+ } | {
87
+ addLabel: LabelActionBody;
88
+ } | {
89
+ addChatLabel: ChatLabelAssociationActionBody;
90
+ } | {
91
+ removeChatLabel: ChatLabelAssociationActionBody;
92
+ } | {
93
+ addMessageLabel: MessageLabelAssociationActionBody;
94
+ } | {
95
+ removeMessageLabel: MessageLabelAssociationActionBody;
96
+ };
97
+ export type InitialReceivedChatsState = {
98
+ [jid: string]: {
99
+ /** the last message received from the other party */
100
+ lastMsgRecvTimestamp?: number;
101
+ /** the absolute last message in the chat */
102
+ lastMsgTimestamp: number;
103
+ };
104
+ };
105
+ export type InitialAppStateSyncOptions = {
106
+ accountSettings: AccountSettings;
107
+ };
@@ -1,13 +1,12 @@
1
1
  export interface Contact {
2
- id: string
3
- lid?: string
2
+ id: string;
3
+ lid?: string;
4
4
  /** name of the contact, you have saved on your WA */
5
- name?: string
5
+ name?: string;
6
6
  /** name of the contact, the contact has set on their own on WA */
7
- notify?: string
7
+ notify?: string;
8
8
  /** I have no idea */
9
- verifiedName?: string
10
- // Baileys Added
9
+ verifiedName?: string;
11
10
  /**
12
11
  * Url of the profile picture of the contact
13
12
  *
@@ -15,6 +14,6 @@ export interface Contact {
15
14
  * null => if the profile picture has not been set (default profile picture)
16
15
  * any other string => url of the profile picture
17
16
  */
18
- imgUrl?: string | null | 'changed'
19
- status?: string
20
- }
17
+ imgUrl?: string | null | 'changed';
18
+ status?: string;
19
+ }