Skip to content

Commit

Permalink
fix: Fixed mentionedList detection (fix #473)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jun 18, 2022
1 parent 7f01c85 commit 5479679
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/chat/functions/prepareRawMessage.ts
Expand Up @@ -15,6 +15,7 @@
*/

import { assertWid } from '../../assert';
import { getParticipants } from '../../group';
import { WPPError } from '../../util';
import {
ChatModel,
Expand Down Expand Up @@ -101,6 +102,7 @@ export async function prepareRawMessage<T extends RawMessage>(
*/
if (
options.detectMentioned &&
chat.isGroup &&
(!options.mentionedList || !options.mentionedList.length)
) {
const text = message.type === 'chat' ? message.body : message.caption;
Expand All @@ -109,10 +111,18 @@ export async function prepareRawMessage<T extends RawMessage>(

const ids = text?.match(/(?<=@)(\d+)\b/g) || [];

for (const id of ids) {
try {
options.mentionedList.push(assertWid(id));
} catch (err) {}
if (ids.length > 0) {
const participants = (await getParticipants(chat.id)).map((p) =>
p.id.toString()
);

for (const id of ids) {
const wid = `${id}@c.us`;
if (!participants.includes(wid)) {
continue;
}
options.mentionedList.push(wid);
}
}
}

Expand Down

0 comments on commit 5479679

Please sign in to comment.