Skip to content

Commit 874f8c4

Browse files
committed
feat: Added client.onMessageEdit event (close #2092)
1 parent 2ea13c3 commit 874f8c4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/api/helpers/exposed.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export enum ExposedFn {
1919
OnMessage = 'onMessage',
2020
OnAnyMessage = 'onAnyMessage',
2121
onAck = 'onAck',
22+
onMessageEdit = 'onMessageEdit',
2223
onNotificationMessage = 'onNotificationMessage',
2324
onParticipantsChanged = 'onParticipantsChanged',
2425
onStateChange = 'onStateChange',

src/api/layers/listener.layer.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ declare global {
4545
onStreamChange: any;
4646
onIncomingCall: any;
4747
onAck: any;
48+
onMessageEdit: any;
4849
}
4950
}
5051

@@ -144,6 +145,21 @@ export class ListenerLayer extends ProfileLayer {
144145
} catch (error) {
145146
console.error(error);
146147
}
148+
try {
149+
if (!window['onMessageEdit'].exposed) {
150+
WPP.on('chat.msg_edited', (data) => {
151+
const eventData = {
152+
chat: data.chat,
153+
id: data.id,
154+
msg: WAPI.processMessageObj(data.msg, true, false),
155+
};
156+
window['onMessageEdit'](eventData);
157+
});
158+
window['onMessageEdit'].exposed = true;
159+
}
160+
} catch (error) {
161+
console.error(error);
162+
}
147163
try {
148164
if (!window['onAnyMessage'].exposed) {
149165
WPP.on('chat.new_message', (msg) => {
@@ -404,6 +420,16 @@ export class ListenerLayer extends ProfileLayer {
404420
return this.registerEvent(ExposedFn.onAck, callback);
405421
}
406422

423+
/**
424+
* @event Listens to message edited changes
425+
* @returns Disposable object to stop the listening
426+
*/
427+
public onMessageEdit(
428+
callback: (chat: Wid, id: string, msg: Message) => void
429+
) {
430+
return this.registerEvent(ExposedFn.onMessageEdit, callback);
431+
}
432+
407433
/**
408434
* Listens to real-time location events of all chats
409435
* @event Real-time location events

0 commit comments

Comments
 (0)