Skip to content

Commit

Permalink
feat: Added chat.msg_edited event (close #1620) (#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jan 29, 2024
1 parent 1fcdcdd commit 06def0a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/chat/events/eventTypes.ts
Expand Up @@ -75,6 +75,16 @@ export interface ChatEventTypes {
*/
ids: MsgKey[];
};

/**
* On Message edit
*/
'chat.msg_edited': {
chat: Wid;
id: string;
msg: MsgModel;
};

'chat.live_location_start': {
id: Wid;
msgId: MsgKey;
Expand Down
1 change: 1 addition & 0 deletions src/chat/events/index.ts
Expand Up @@ -23,3 +23,4 @@ import './registerPresenceChange';
import './registerReactionsEvent';
import './registerRevokeMessageEvent';
import './registerLabelEvent';
import './registerEditedMessageEvent';
33 changes: 33 additions & 0 deletions src/chat/events/registerEditedMessageEvent.ts
@@ -0,0 +1,33 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { internalEv } from '../../eventEmitter';
import * as webpack from '../../webpack';
import { MsgModel, MsgStore } from '../../whatsapp';

webpack.onFullReady(registerAckMessageEvent);

function registerAckMessageEvent() {
MsgStore.on('change:latestEditMsgKey', (msg: MsgModel) => {
queueMicrotask(() => {
internalEv.emit('chat.msg_edited', {
chat: msg.to!,
id: msg.id.toString(),
msg: msg,
});
});
});
}
7 changes: 2 additions & 5 deletions src/util/types.ts
Expand Up @@ -35,11 +35,8 @@ export type NonFunctionPropertyNames<T> = {

export type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;

export type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X
? 1
: 2) extends <T>() => T extends Y ? 1 : 2
? A
: B;
export type IfEquals<X, Y, A = X, B = never> =
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;

export type WritablePropertiesNames<T> = {
[P in keyof T]-?: IfEquals<
Expand Down

0 comments on commit 06def0a

Please sign in to comment.