Skip to content

Commit

Permalink
fix: Fixed getMessage return for serialization (fix #957)
Browse files Browse the repository at this point in the history
edgardmessias committed Mar 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e3681c1 commit f5a3bb9
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
@@ -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];
}
9 changes: 8 additions & 1 deletion src/chat/functions/getMessages.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f5a3bb9

Please sign in to comment.