From f3ae21c716bbd1760e04cf7085bb75a8a5850766 Mon Sep 17 00:00:00 2001 From: opsJson <54485405+opsJson@users.noreply.github.com> Date: Tue, 28 Jan 2025 20:37:52 -0300 Subject: [PATCH] fix: Fixed WPP.chat.openChatAt function (#2630) --- src/chat/functions/openChatAt.ts | 10 +++++++--- src/whatsapp/functions/getSearchContext.ts | 4 ++-- src/whatsapp/misc/Cmd.ts | 6 +++++- src/whatsapp/models/ChatModel.ts | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/chat/functions/openChatAt.ts b/src/chat/functions/openChatAt.ts index fd3862a283..9a131635da 100644 --- a/src/chat/functions/openChatAt.ts +++ b/src/chat/functions/openChatAt.ts @@ -39,7 +39,11 @@ export async function openChatAt( const msg = await getMessageById(messageId); - const result = getSearchContext(chat, msg); - - return await Cmd.openChatAt(chat, result); + try { + const msgContext = getSearchContext(chat, msg); + return await Cmd.openChatAt(chat, msgContext); + } catch (e) { + const msgContext = getSearchContext(chat, msg.id._serialized); + return await Cmd.openChatAt({ chat, msgContext }); + } } diff --git a/src/whatsapp/functions/getSearchContext.ts b/src/whatsapp/functions/getSearchContext.ts index f04d5d5468..ce2fa69f10 100644 --- a/src/whatsapp/functions/getSearchContext.ts +++ b/src/whatsapp/functions/getSearchContext.ts @@ -22,8 +22,8 @@ import { ChatModel, MsgModel } from '../models'; * @whatsapp 738599 >= 2.2242.5 */ export declare function getSearchContext( - chat: ChatModel, - msg: MsgModel | MsgKey, + chat: ChatModel | string, + msg: MsgModel | MsgKey | string, options?: { isQuotedMsgAvailable: boolean; } diff --git a/src/whatsapp/misc/Cmd.ts b/src/whatsapp/misc/Cmd.ts index 530d37cdc8..0593e1ea08 100644 --- a/src/whatsapp/misc/Cmd.ts +++ b/src/whatsapp/misc/Cmd.ts @@ -107,8 +107,12 @@ export declare class CmdClass extends EventEmitter { _openChat(e?: any, t?: any): void; openChatAt( chat: ChatModel, - context: ReturnType + msgContext: ReturnType ): Promise; + openChatAt(params?: { + chat: ChatModel; + msgContext: ReturnType; + }): Promise; openChatFromUnread(chat: ChatModel): Promise; openChatBottom(chat: ChatModel): Promise; scrollToPtt(e?: any): void; diff --git a/src/whatsapp/models/ChatModel.ts b/src/whatsapp/models/ChatModel.ts index e67ff80f77..4a1c209fc6 100644 --- a/src/whatsapp/models/ChatModel.ts +++ b/src/whatsapp/models/ChatModel.ts @@ -174,7 +174,8 @@ export declare class ChatModel extends ModelChatBase { isMostRecentCMC(e?: any): boolean; loadRecentMsgs(e?: any): any; getSearchContext?( - msg: MsgModel | MsgKey, + chat: ChatModel | string, + msg: MsgModel | MsgKey | string, options?: { isQuotedMsgAvailable: boolean; }