Skip to content

Commit

Permalink
fix: Fixed chat.new_reaction event in 2.3000.x (#2021)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta authored Jun 18, 2024
1 parent c2f470a commit 65b35e5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
57 changes: 40 additions & 17 deletions src/chat/events/registerReactionsEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,51 @@ import { createOrUpdateReactions } from '../../whatsapp/functions';

webpack.onFullReady(register);

const now = Date.now();
const reactions: string[] = [];

function register() {
wrapModuleFunction(createOrUpdateReactions, (func, ...args) => {
const [data] = args;

for (const d of data) {
const [data]: any = args;
const now = Date.now();
if (Array.isArray(data)) {
for (const d of data) {
try {
if ((d as any).t < now) {
continue;
}
internalEv.emitAsync('chat.new_reaction', {
id: MsgKey.fromString((d as any).id),
orphan: d.orphan,
orphanReason: d.orphanReason,
msgId: MsgKey.fromString((d as any).reactionParentKey),
reactionText: d.reactionText,
read: d.read,
sender: createWid((d as any).from)!,
timestamp: (d as any).t,
});
} catch (error) {}
}
} else {
try {
if (d.timestamp < now) {
continue;
}
const inNewReaction = (args as any)[1];
if (inNewReaction) {
if (reactions[data.msgKey]) return func(...args);
reactions[data.msgKey] = data;

internalEv.emitAsync('chat.new_reaction', {
id: MsgKey.fromString(d.msgKey),
orphan: d.orphan,
orphanReason: d.orphanReason,
msgId: MsgKey.fromString(d.parentMsgKey),
reactionText: d.reactionText,
read: d.read,
sender: createWid(d.senderUserJid)!,
timestamp: d.timestamp,
});
internalEv.emitAsync('chat.new_reaction', {
id: MsgKey.fromString(data.msgKey),
orphan: data.orphan,
orphanReason: null,
msgId: MsgKey.fromString(data.parentMsgKey),
reactionText: data.reactionText,
read: data.read,
sender: createWid(data.senderUserJid)!,
timestamp: data.t,
});
setTimeout(() => {
delete reactions[data.msgKey];
}, 10000);
}
} catch (error) {}
}

Expand Down
5 changes: 3 additions & 2 deletions src/whatsapp/functions/createOrUpdateReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ReactionData {

/** @whatsapp 7394
* @whatsapp 307394 >= 2.2222.8
* @whatsapp WAWebReactionsMsgAction >= 2.3000.x
*/
export declare function createOrUpdateReactions(
data: ReactionData[]
Expand All @@ -37,7 +38,7 @@ export declare function createOrUpdateReactions(
exportModule(
exports,
{
createOrUpdateReactions: 'createOrUpdateReactions',
createOrUpdateReactions: ['addOrUpdateReactionsModelCollection'],
},
(m) => m.createOrUpdateReactions
(m) => m.addOrUpdateReactionsModelCollection
);

0 comments on commit 65b35e5

Please sign in to comment.