whatsapp-web.js 1.19.0 → 1.19.2
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/package.json +1 -1
- package/src/Client.js +8 -10
- package/src/structures/GroupChat.js +46 -24
- package/src/util/Injected.js +6 -7
package/package.json
CHANGED
package/src/Client.js
CHANGED
|
@@ -774,7 +774,7 @@ class Client extends EventEmitter {
|
|
|
774
774
|
*/
|
|
775
775
|
async getInviteInfo(inviteCode) {
|
|
776
776
|
return await this.pupPage.evaluate(inviteCode => {
|
|
777
|
-
return window.Store.InviteInfo.
|
|
777
|
+
return window.Store.InviteInfo.queryGroupInvite(inviteCode);
|
|
778
778
|
}, inviteCode);
|
|
779
779
|
}
|
|
780
780
|
|
|
@@ -784,11 +784,11 @@ class Client extends EventEmitter {
|
|
|
784
784
|
* @returns {Promise<string>} Id of the joined Chat
|
|
785
785
|
*/
|
|
786
786
|
async acceptInvite(inviteCode) {
|
|
787
|
-
const
|
|
788
|
-
return await window.Store.Invite.
|
|
787
|
+
const res = await this.pupPage.evaluate(async inviteCode => {
|
|
788
|
+
return await window.Store.Invite.joinGroupViaInvite(inviteCode);
|
|
789
789
|
}, inviteCode);
|
|
790
790
|
|
|
791
|
-
return
|
|
791
|
+
return res.gid._serialized;
|
|
792
792
|
}
|
|
793
793
|
|
|
794
794
|
/**
|
|
@@ -1095,19 +1095,17 @@ class Client extends EventEmitter {
|
|
|
1095
1095
|
|
|
1096
1096
|
const createRes = await this.pupPage.evaluate(async (name, participantIds) => {
|
|
1097
1097
|
const participantWIDs = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
1098
|
-
|
|
1099
|
-
const res = await window.Store.GroupUtils.sendCreateGroup(name, participantWIDs, undefined, id);
|
|
1100
|
-
return res;
|
|
1098
|
+
return await window.Store.GroupUtils.createGroup(name, participantWIDs, 0);
|
|
1101
1099
|
}, name, participants);
|
|
1102
1100
|
|
|
1103
1101
|
const missingParticipants = createRes.participants.reduce(((missing, c) => {
|
|
1104
|
-
const id =
|
|
1105
|
-
const statusCode = c
|
|
1102
|
+
const id = c.wid._serialized;
|
|
1103
|
+
const statusCode = c.error ? c.error.toString() : '200';
|
|
1106
1104
|
if (statusCode != 200) return Object.assign(missing, { [id]: statusCode });
|
|
1107
1105
|
return missing;
|
|
1108
1106
|
}), {});
|
|
1109
1107
|
|
|
1110
|
-
return { gid: createRes.
|
|
1108
|
+
return { gid: createRes.wid, missingParticipants };
|
|
1111
1109
|
}
|
|
1112
1110
|
|
|
1113
1111
|
/**
|
|
@@ -59,10 +59,15 @@ class GroupChat extends Chat {
|
|
|
59
59
|
* @returns {Promise<Object>}
|
|
60
60
|
*/
|
|
61
61
|
async addParticipants(participantIds) {
|
|
62
|
-
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
62
|
+
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
63
63
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const chat = await window.Store.Chat.find(chatWid);
|
|
65
|
+
const participants = await Promise.all(participantIds.map(async p => {
|
|
66
|
+
const wid = window.Store.WidFactory.createWid(p);
|
|
67
|
+
return await window.Store.Contact.get(wid);
|
|
68
|
+
}));
|
|
69
|
+
await window.Store.GroupParticipants.addParticipants(chat, participants);
|
|
70
|
+
return { status: 200 };
|
|
66
71
|
}, this.id._serialized, participantIds);
|
|
67
72
|
}
|
|
68
73
|
|
|
@@ -72,10 +77,14 @@ class GroupChat extends Chat {
|
|
|
72
77
|
* @returns {Promise<Object>}
|
|
73
78
|
*/
|
|
74
79
|
async removeParticipants(participantIds) {
|
|
75
|
-
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
80
|
+
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
76
81
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
77
|
-
const
|
|
78
|
-
|
|
82
|
+
const chat = await window.Store.Chat.find(chatWid);
|
|
83
|
+
const participants = participantIds.map(p => {
|
|
84
|
+
return chat.groupMetadata.participants.get(p);
|
|
85
|
+
}).filter(p => Boolean(p));
|
|
86
|
+
await window.Store.GroupParticipants.removeParticipants(chat, participants);
|
|
87
|
+
return { status: 200 };
|
|
79
88
|
}, this.id._serialized, participantIds);
|
|
80
89
|
}
|
|
81
90
|
|
|
@@ -85,10 +94,14 @@ class GroupChat extends Chat {
|
|
|
85
94
|
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
|
86
95
|
*/
|
|
87
96
|
async promoteParticipants(participantIds) {
|
|
88
|
-
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
97
|
+
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
89
98
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
90
|
-
const
|
|
91
|
-
|
|
99
|
+
const chat = await window.Store.Chat.find(chatWid);
|
|
100
|
+
const participants = participantIds.map(p => {
|
|
101
|
+
return chat.groupMetadata.participants.get(p);
|
|
102
|
+
}).filter(p => Boolean(p));
|
|
103
|
+
await window.Store.GroupParticipants.promoteParticipants(chat, participants);
|
|
104
|
+
return { status: 200 };
|
|
92
105
|
}, this.id._serialized, participantIds);
|
|
93
106
|
}
|
|
94
107
|
|
|
@@ -98,10 +111,14 @@ class GroupChat extends Chat {
|
|
|
98
111
|
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
|
99
112
|
*/
|
|
100
113
|
async demoteParticipants(participantIds) {
|
|
101
|
-
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
114
|
+
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
102
115
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
103
|
-
const
|
|
104
|
-
|
|
116
|
+
const chat = await window.Store.Chat.find(chatWid);
|
|
117
|
+
const participants = participantIds.map(p => {
|
|
118
|
+
return chat.groupMetadata.participants.get(p);
|
|
119
|
+
}).filter(p => Boolean(p));
|
|
120
|
+
await window.Store.GroupParticipants.demoteParticipants(chat, participants);
|
|
121
|
+
return { status: 200 };
|
|
105
122
|
}, this.id._serialized, participantIds);
|
|
106
123
|
}
|
|
107
124
|
|
|
@@ -114,7 +131,8 @@ class GroupChat extends Chat {
|
|
|
114
131
|
const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
|
|
115
132
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
116
133
|
try {
|
|
117
|
-
|
|
134
|
+
await window.Store.GroupUtils.setGroupSubject(chatWid, subject);
|
|
135
|
+
return true;
|
|
118
136
|
} catch (err) {
|
|
119
137
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
120
138
|
throw err;
|
|
@@ -136,7 +154,8 @@ class GroupChat extends Chat {
|
|
|
136
154
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
137
155
|
let descId = window.Store.GroupMetadata.get(chatWid).descId;
|
|
138
156
|
try {
|
|
139
|
-
|
|
157
|
+
await window.Store.GroupUtils.setGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
|
|
158
|
+
return true;
|
|
140
159
|
} catch (err) {
|
|
141
160
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
142
161
|
throw err;
|
|
@@ -157,7 +176,8 @@ class GroupChat extends Chat {
|
|
|
157
176
|
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
|
|
158
177
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
159
178
|
try {
|
|
160
|
-
|
|
179
|
+
await window.Store.GroupUtils.setGroupProperty(chatWid, 'announcement', adminsOnly ? 1 : 0);
|
|
180
|
+
return true;
|
|
161
181
|
} catch (err) {
|
|
162
182
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
163
183
|
throw err;
|
|
@@ -179,7 +199,8 @@ class GroupChat extends Chat {
|
|
|
179
199
|
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
|
|
180
200
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
181
201
|
try {
|
|
182
|
-
|
|
202
|
+
await window.Store.GroupUtils.setGroupProperty(chatWid, 'restrict', adminsOnly ? 1 : 0);
|
|
203
|
+
return true;
|
|
183
204
|
} catch (err) {
|
|
184
205
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
185
206
|
throw err;
|
|
@@ -197,12 +218,12 @@ class GroupChat extends Chat {
|
|
|
197
218
|
* @returns {Promise<string>} Group's invite code
|
|
198
219
|
*/
|
|
199
220
|
async getInviteCode() {
|
|
200
|
-
const
|
|
221
|
+
const codeRes = await this.client.pupPage.evaluate(async chatId => {
|
|
201
222
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
202
|
-
return window.Store.Invite.
|
|
223
|
+
return window.Store.Invite.queryGroupInviteCode(chatWid);
|
|
203
224
|
}, this.id._serialized);
|
|
204
225
|
|
|
205
|
-
return code;
|
|
226
|
+
return codeRes.code;
|
|
206
227
|
}
|
|
207
228
|
|
|
208
229
|
/**
|
|
@@ -210,12 +231,12 @@ class GroupChat extends Chat {
|
|
|
210
231
|
* @returns {Promise<string>} New invite code
|
|
211
232
|
*/
|
|
212
233
|
async revokeInvite() {
|
|
213
|
-
const
|
|
234
|
+
const codeRes = await this.client.pupPage.evaluate(chatId => {
|
|
214
235
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
215
|
-
return window.Store.Invite.
|
|
236
|
+
return window.Store.Invite.resetGroupInviteCode(chatWid);
|
|
216
237
|
}, this.id._serialized);
|
|
217
238
|
|
|
218
|
-
return code;
|
|
239
|
+
return codeRes.code;
|
|
219
240
|
}
|
|
220
241
|
|
|
221
242
|
/**
|
|
@@ -223,9 +244,10 @@ class GroupChat extends Chat {
|
|
|
223
244
|
* @returns {Promise}
|
|
224
245
|
*/
|
|
225
246
|
async leave() {
|
|
226
|
-
await this.client.pupPage.evaluate(chatId => {
|
|
247
|
+
await this.client.pupPage.evaluate(async chatId => {
|
|
227
248
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
228
|
-
|
|
249
|
+
const chat = await window.Store.Chat.find(chatWid);
|
|
250
|
+
return window.Store.GroupUtils.sendExitGroup(chat);
|
|
229
251
|
}, this.id._serialized);
|
|
230
252
|
}
|
|
231
253
|
|
package/src/util/Injected.js
CHANGED
|
@@ -14,8 +14,8 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
14
14
|
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
|
|
15
15
|
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
|
|
16
16
|
window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
|
|
17
|
-
window.Store.Invite = window.mR.findModule('
|
|
18
|
-
window.Store.InviteInfo = window.mR.findModule('
|
|
17
|
+
window.Store.Invite = window.mR.findModule('resetGroupInviteCode')[0];
|
|
18
|
+
window.Store.InviteInfo = window.mR.findModule('queryGroupInvite')[0];
|
|
19
19
|
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
|
|
20
20
|
window.Store.MediaPrep = window.mR.findModule('MediaPrep')[0];
|
|
21
21
|
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
|
@@ -41,7 +41,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
41
41
|
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
|
|
42
42
|
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
|
|
43
43
|
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
|
|
44
|
-
window.Store.GroupParticipants = window.mR.findModule('
|
|
44
|
+
window.Store.GroupParticipants = window.mR.findModule('promoteParticipants')[1];
|
|
45
45
|
window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0];
|
|
46
46
|
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
|
|
47
47
|
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
|
|
@@ -60,9 +60,9 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
window.Store.GroupUtils = {
|
|
63
|
-
...window.mR.findModule('
|
|
64
|
-
...window.mR.findModule('
|
|
65
|
-
...window.mR.findModule('
|
|
63
|
+
...window.mR.findModule('createGroup')[0],
|
|
64
|
+
...window.mR.findModule('setGroupDescription')[0],
|
|
65
|
+
...window.mR.findModule('sendExitGroup')[0]
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
if (!window.Store.Chat._find) {
|
|
@@ -271,7 +271,6 @@ exports.LoadUtils = () => {
|
|
|
271
271
|
...ephemeralFields,
|
|
272
272
|
...locationOptions,
|
|
273
273
|
...attOptions,
|
|
274
|
-
...(Object.keys(attOptions).length > 0 ? attOptions.toJSON() : {}),
|
|
275
274
|
...quotedMsgOptions,
|
|
276
275
|
...vcardOptions,
|
|
277
276
|
...buttonOptions,
|