From 5953b2f997f33d71714cfe36452e5ebca91404a6 Mon Sep 17 00:00:00 2001 From: Geoff Hayman Date: Mon, 29 Apr 2024 13:20:33 -0700 Subject: [PATCH 1/3] Fixed isLoggedIn() - #2724 --- src/lib/wapi/functions/is-logged-in.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/wapi/functions/is-logged-in.js b/src/lib/wapi/functions/is-logged-in.js index f237f2fec..bc2f91257 100644 --- a/src/lib/wapi/functions/is-logged-in.js +++ b/src/lib/wapi/functions/is-logged-in.js @@ -1,7 +1,6 @@ export function isLoggedIn(done) { // Contact always exists when logged in - const isLogged = - window.Store.Contact && window.Store.Contact.checksum !== undefined; + const isLogged = window.Store.Contact && window.Store.Contact.length > 0; if (done !== undefined) done(isLogged); return isLogged; From 3c44baee978def45a5fcfffafc027620325868c2 Mon Sep 17 00:00:00 2001 From: Geoff Hayman Date: Thu, 23 May 2024 15:44:47 -0700 Subject: [PATCH 2/3] fix to stop 'Multiple targets are not supported in headless mode.' on startup --- src/config/puppeteer.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/puppeteer.config.ts b/src/config/puppeteer.config.ts index ebac88741..6f2a92a20 100644 --- a/src/config/puppeteer.config.ts +++ b/src/config/puppeteer.config.ts @@ -49,8 +49,8 @@ const puppeteerConfig = { '--password-store=basic', '--use-mock-keychain', '--enable-blink-features=IdleDetection', - '--export-tagged-pdf', - 'about:blank' + '--export-tagged-pdf' + // 'about:blank' ] }; From e756ed32b96fbb1834fcf67ae127170ea596707d Mon Sep 17 00:00:00 2001 From: Geoff Hayman Date: Fri, 12 Jul 2024 14:32:01 -0700 Subject: [PATCH 3/3] Added onMessageEdit() and onMessageDelete() event notifications --- README.md | 12 +++++- src/api/helpers/exposed.enum.ts | 2 + src/api/layers/listener.layer.ts | 68 ++++++++++++++++++++++++++++++-- src/types/WAPI.d.ts | 2 + 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f40ef8a64..bf632c12b 100644 --- a/README.md +++ b/README.md @@ -834,7 +834,17 @@ client.onAnyMessage(message => { // Listen to messages client.onMessage(message => { - ... +... +}) + +// Listen for messages that have been edited +client.onMessageEdit(message => { +... +}) + +// Listen for messages that have been deleted +client.onMessageDelete(message => { +... }) // Listen to state changes diff --git a/src/api/helpers/exposed.enum.ts b/src/api/helpers/exposed.enum.ts index 24f7d793e..bab983b06 100644 --- a/src/api/helpers/exposed.enum.ts +++ b/src/api/helpers/exposed.enum.ts @@ -1,5 +1,7 @@ export enum ExposedFn { OnMessage = 'onMessage', + OnMessageEdit = 'onMessageEdit', + OnMessageDelete = 'onMessageDelete', OnAnyMessage = 'onAnyMessage', onAck = 'onAck', onParticipantsChanged = 'onParticipantsChanged', diff --git a/src/api/layers/listener.layer.ts b/src/api/layers/listener.layer.ts index b6954dc6b..547d58115 100644 --- a/src/api/layers/listener.layer.ts +++ b/src/api/layers/listener.layer.ts @@ -22,6 +22,8 @@ declare global { interface Window { onMessage: any; onAnyMessage: any; + onMessageEdit: any; + onMessageDelete: any; onStateChange: any; onIncomingCall: any; onAck: any; @@ -75,7 +77,7 @@ export class ListenerLayer extends ProfileLayer { } } - this.addMsg(); + await this.addMsg(); await this.page .evaluate(() => { window.WAPI.onInterfaceChange((e: any) => { @@ -104,6 +106,12 @@ export class ListenerLayer extends ProfileLayer { window.WAPI.onAck((e: any) => { window.onAck(e); }); + window.WAPI.onMessageEdit((e: any) => { + window.onMessageEdit(e); + }); + window.WAPI.onMessageDelete((e: any) => { + window.onMessageDelete(e); + }); window.WAPI.onPoll((e: any) => { window.onPoll(e); }); @@ -129,6 +137,25 @@ export class ListenerLayer extends ProfileLayer { } } }); + + window.Store.Msg.on( + 'change:body change:caption', + async (newMessage) => { + if (newMessage && newMessage.isNewMsg) { + const processMessageObj = await window.WAPI.processMessageObj( + newMessage, + true, + false + ); + + if (newMessage.type == 'revoked') { + window.onMessageDelete(processMessageObj); + } else { + window.onMessageEdit(processMessageObj); + } + } + } + ); // } catch { } }) .catch(() => {}); @@ -150,8 +177,7 @@ export class ListenerLayer extends ProfileLayer { /** * @event Listens to all new messages - * @param to callback - * @fires Message + * @param fn */ public async onAnyMessage(fn: (message: Message) => void) { this.listenerEmitter.on(ExposedFn.OnAnyMessage, (msg) => { @@ -167,6 +193,42 @@ export class ListenerLayer extends ProfileLayer { }; } + /** + * @event Listens for edited message + * @param fn + */ + public async onMessageEdit(fn: (message: Message) => void) { + this.listenerEmitter.on(ExposedFn.OnMessageEdit, (msg) => { + fn(msg); + }); + + return { + dispose: () => { + this.listenerEmitter.off(ExposedFn.OnMessageEdit, (msg) => { + fn(msg); + }); + } + }; + } + + /** + * @event Listens for deleted message + * @param fn + */ + public async onMessageDelete(fn: (message: Message) => void) { + this.listenerEmitter.on(ExposedFn.OnMessageDelete, (msg) => { + fn(msg); + }); + + return { + dispose: () => { + this.listenerEmitter.off(ExposedFn.OnMessageDelete, (msg) => { + fn(msg); + }); + } + }; + } + /** * @event Listens to messages received * @returns Observable stream of messages diff --git a/src/types/WAPI.d.ts b/src/types/WAPI.d.ts index 161e3d868..fbd8bf9f0 100644 --- a/src/types/WAPI.d.ts +++ b/src/types/WAPI.d.ts @@ -14,6 +14,8 @@ import { interface WAPI { addParticipant: (groupId: string, contactId: string | string[]) => boolean; onAnyMessage: (callback: Function) => void; + onMessageEdit: (callback: Function) => void; + onMessageDelete: (callback: Function) => void; archiveChat: (chatId: string, option: boolean) => boolean; arrayBufferToBase64: (buffer: ArrayBuffer) => string; blockContact: (messageId: string) => boolean;