Skip to content

Commit

Permalink
fix: Fixed getMessage return for serialization (fix wppconnect-team#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Mar 29, 2023
1 parent e3681c1 commit f5a3bb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/chat/functions/getMessageById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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];
}
Expand Down
9 changes: 8 additions & 1 deletion src/chat/functions/getMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '..';

Expand Down Expand Up @@ -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;
}

0 comments on commit f5a3bb9

Please sign in to comment.