Skip to content

Commit

Permalink
fix: Fixed send message (DuplicateMessageError) (fix #1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed May 19, 2023
1 parent 4e62905 commit d95b140
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/chat/functions/generateMessageID.ts
Expand Up @@ -23,7 +23,9 @@ import { randomMessageId } from '../../whatsapp/functions';
*
* @category Message
*/
export function generateMessageID(chat: string | ChatModel | Wid): MsgKey {
export async function generateMessageID(
chat: string | ChatModel | Wid
): Promise<MsgKey> {
const from = UserPrefs.getMaybeMeUser();
let to: Wid;

Expand All @@ -44,7 +46,7 @@ export function generateMessageID(chat: string | ChatModel | Wid): MsgKey {
return new MsgKey({
from,
to,
id: randomMessageId(),
id: await Promise.resolve(randomMessageId()),
participant,
selfDir: 'out',
});
Expand Down
2 changes: 1 addition & 1 deletion src/chat/functions/prepareRawMessage.ts
Expand Up @@ -91,7 +91,7 @@ export async function prepareRawMessage<T extends RawMessage>(
}

if (!message.id) {
message.id = generateMessageID(chat);
message.id = await generateMessageID(chat);
}

if (options.mentionedList && !Array.isArray(options.mentionedList)) {
Expand Down
2 changes: 1 addition & 1 deletion src/group/functions/setDescription.ts
Expand Up @@ -51,7 +51,7 @@ export async function setDescription(
/**
* @todo change randomMessageId to randomHex
*/
const tagId = randomMessageId();
const tagId = await Promise.resolve(randomMessageId());

await sendSetGroupDescription(
groupChat.id,
Expand Down
4 changes: 3 additions & 1 deletion src/whatsapp/functions/randomId.ts
Expand Up @@ -19,8 +19,10 @@ import { exportModule } from '../exportModule';
/** @whatsapp 65212
* @whatsapp 15860 >= 2.2204.13
* @whatsapp 465212 >= 2.2222.8
* @returns Promise for @whatsapp >= 2.2321.4
* @returns string for @whatsapp < 2.2321.4
*/
export declare function randomMessageId(): string;
export declare function randomMessageId(): string | Promise<string>;

exportModule(
exports,
Expand Down

0 comments on commit d95b140

Please sign in to comment.