diff --git a/src/chat/functions/getMessageById.ts b/src/chat/functions/getMessageById.ts index 09199b42ed..f5d255d60b 100644 --- a/src/chat/functions/getMessageById.ts +++ b/src/chat/functions/getMessageById.ts @@ -54,7 +54,7 @@ export async function getMessageById( const msgsKeys = ids.map((id) => MsgKey.fromString(id.toString())); - const msgs: MsgModel[] = []; + let msgs: MsgModel[] = []; for (const msgKey of msgsKeys) { let msg = MsgStore.get(msgKey); @@ -85,6 +85,13 @@ export async function getMessageById( msgs.push(msg); } + msgs = msgs.map((m: any) => { + if (m instanceof MsgModel) { + return m; + } + return MsgStore.get(m) || new MsgModel(m); + }); + if (isSingle) { return msgs[0]; } diff --git a/src/chat/functions/getMessages.ts b/src/chat/functions/getMessages.ts index 7afe34b61d..e1a526be84 100644 --- a/src/chat/functions/getMessages.ts +++ b/src/chat/functions/getMessages.ts @@ -16,7 +16,7 @@ import { assertGetChat } from '../../assert'; import { isMultiDevice } from '../../conn'; -import { MsgKey, MsgStore, Wid } from '../../whatsapp'; +import { MsgKey, MsgModel, MsgStore, Wid } from '../../whatsapp'; import { msgFindQuery, MsgFindQueryParams } from '../../whatsapp/functions'; import { RawMessage } from '..'; @@ -157,5 +157,12 @@ export async function getMessages( } } + msgs = msgs.map((m: any) => { + if (m instanceof MsgModel) { + return m; + } + return MsgStore.get(m) || new MsgModel(m); + }); + return msgs; }