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.
@@ -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
- let chatWid = window.Store.WidFactory.createWid(chatId);
19
- let chat = await window.Store.Chat.find(chatWid);
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.Store.Chat.get(chatId);
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.Store.Chat.get(chatId);
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
- let chat = await window.Store.Chat.find(msg.id.remote);
54
- let searchContext = await window.Store.SearchContext(chat,msg);
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};