whatsapp-web-sj.js 1.26.0 → 1.31.0
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/README.md +2 -2
- package/example.js +47 -1
- package/index.d.ts +249 -22
- package/index.js +2 -0
- package/package.json +7 -3
- package/src/Client.js +716 -275
- package/src/authStrategies/LocalAuth.js +4 -2
- package/src/authStrategies/RemoteAuth.js +11 -5
- package/src/factories/ChatFactory.js +7 -2
- package/src/structures/Broadcast.js +69 -0
- package/src/structures/Channel.js +382 -0
- package/src/structures/Chat.js +23 -7
- package/src/structures/GroupChat.js +11 -13
- package/src/structures/Location.js +1 -0
- package/src/structures/Message.js +17 -24
- package/src/structures/index.js +3 -1
- package/src/util/Constants.js +1 -1
- package/src/util/Injected/Store.js +57 -9
- package/src/util/Injected/Utils.js +277 -155
- package/src/util/InterfaceController.js +9 -10
- package/src/util/Puppeteer.js +23 -0
@@ -14,10 +14,9 @@ class InterfaceController {
|
|
14
14
|
* @param {string} chatId ID of the chat window that will be opened
|
15
15
|
*/
|
16
16
|
async openChatWindow(chatId) {
|
17
|
-
await this.pupPage.evaluate(async chatId => {
|
18
|
-
|
19
|
-
|
20
|
-
await window.Store.Cmd.openChatAt(chat);
|
17
|
+
await this.pupPage.evaluate(async (chatId) => {
|
18
|
+
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
19
|
+
await window.Store.Cmd.openChatBottom(chat);
|
21
20
|
}, chatId);
|
22
21
|
}
|
23
22
|
|
@@ -27,7 +26,7 @@ class InterfaceController {
|
|
27
26
|
*/
|
28
27
|
async openChatDrawer(chatId) {
|
29
28
|
await this.pupPage.evaluate(async chatId => {
|
30
|
-
let chat = await window.
|
29
|
+
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
31
30
|
await window.Store.Cmd.openDrawerMid(chat);
|
32
31
|
}, chatId);
|
33
32
|
}
|
@@ -38,7 +37,7 @@ class InterfaceController {
|
|
38
37
|
*/
|
39
38
|
async openChatSearch(chatId) {
|
40
39
|
await this.pupPage.evaluate(async chatId => {
|
41
|
-
let chat = await window.
|
40
|
+
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
42
41
|
await window.Store.Cmd.chatSearch(chat);
|
43
42
|
}, chatId);
|
44
43
|
}
|
@@ -48,11 +47,11 @@ class InterfaceController {
|
|
48
47
|
* @param {string} msgId ID of the message that will be scrolled to
|
49
48
|
*/
|
50
49
|
async openChatWindowAt(msgId) {
|
51
|
-
await this.pupPage.evaluate(async msgId => {
|
50
|
+
await this.pupPage.evaluate(async (msgId) => {
|
52
51
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
53
|
-
|
54
|
-
|
55
|
-
await window.Store.Cmd.openChatAt(chat, searchContext);
|
52
|
+
const chat = window.Store.Chat.get(msg.id.remote) ?? await window.Store.Chat.find(msg.id.remote);
|
53
|
+
const searchContext = await window.Store.SearchContext.getSearchContext(chat, msg.id);
|
54
|
+
await window.Store.Cmd.openChatAt({ chat: chat, msgContext: searchContext });
|
56
55
|
}, msgId);
|
57
56
|
}
|
58
57
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* Expose a function to the page if it does not exist
|
3
|
+
*
|
4
|
+
* NOTE:
|
5
|
+
* Rewrite it to 'upsertFunction' after updating Puppeteer to 20.6 or higher
|
6
|
+
* using page.removeExposedFunction
|
7
|
+
* https://pptr.dev/api/puppeteer.page.removeExposedFunction
|
8
|
+
*
|
9
|
+
* @param {import(puppeteer).Page} page
|
10
|
+
* @param {string} name
|
11
|
+
* @param {Function} fn
|
12
|
+
*/
|
13
|
+
async function exposeFunctionIfAbsent(page, name, fn) {
|
14
|
+
const exist = await page.evaluate((name) => {
|
15
|
+
return !!window[name];
|
16
|
+
}, name);
|
17
|
+
if (exist) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
await page.exposeFunction(name, fn);
|
21
|
+
}
|
22
|
+
|
23
|
+
module.exports = {exposeFunctionIfAbsent};
|