Skip to content

Commit

Permalink
fix: Fixed generated message ID for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Oct 17, 2022
1 parent d68f175 commit aceeb89
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/chat/functions/generateMessageID.ts
Expand Up @@ -15,7 +15,7 @@
*/

import { assertWid } from '../../assert';
import { ChatModel, MsgKey, UserPrefs, Wid } from '../../whatsapp';
import { ChatModel, MsgKey, UserPrefs, Wid, WidFactory } from '../../whatsapp';
import { randomMessageId } from '../../whatsapp/functions';

/**
Expand All @@ -24,6 +24,7 @@ import { randomMessageId } from '../../whatsapp/functions';
* @category Message
*/
export function generateMessageID(chat: string | ChatModel | Wid): MsgKey {
const from = UserPrefs.getMaybeMeUser();
let to: Wid;

if (chat instanceof Wid) {
Expand All @@ -34,10 +35,17 @@ export function generateMessageID(chat: string | ChatModel | Wid): MsgKey {
to = assertWid(chat);
}

let participant = undefined;

if (to.isGroup()) {
participant = WidFactory.toUserWid(from);
}

return new MsgKey({
from: UserPrefs.getMaybeMeUser(),
to: to,
from,
to,
id: randomMessageId(),
participant,
selfDir: 'out',
});
}

0 comments on commit aceeb89

Please sign in to comment.