mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
fix: sending media count as unread messages
This commit is contained in:
@@ -165,6 +165,7 @@ const handlMedia = async (
|
|||||||
contactId: msg.fromMe ? null : contact.id,
|
contactId: msg.fromMe ? null : contact.id,
|
||||||
body: msg.body || media.filename,
|
body: msg.body || media.filename,
|
||||||
fromMe: msg.fromMe,
|
fromMe: msg.fromMe,
|
||||||
|
read: msg.fromMe,
|
||||||
mediaUrl: media.filename,
|
mediaUrl: media.filename,
|
||||||
mediaType: media.mimetype.split("/")[0]
|
mediaType: media.mimetype.split("/")[0]
|
||||||
});
|
});
|
||||||
@@ -248,7 +249,7 @@ const wbotMessageListener = (whatsapp: Whatsapp): void => {
|
|||||||
|
|
||||||
// return if it's a media message, it will be handled by media_uploaded event
|
// return if it's a media message, it will be handled by media_uploaded event
|
||||||
|
|
||||||
if (msg.hasMedia || (msg.type !== "chat" && msg.type !== "vcard"))
|
if (!msg.hasMedia && msg.type !== "chat" && msg.type !== "vcard")
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
msgContact = await msg.getContact();
|
msgContact = await msg.getContact();
|
||||||
@@ -281,25 +282,25 @@ const wbotMessageListener = (whatsapp: Whatsapp): void => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wbot.on("media_uploaded", async msg => {
|
// wbot.on("media_uploaded", async msg => {
|
||||||
try {
|
// try {
|
||||||
let groupContact: Contact | undefined;
|
// let groupContact: Contact | undefined;
|
||||||
const msgContact = await wbot.getContactById(msg.to);
|
// const msgContact = await wbot.getContactById(msg.to);
|
||||||
if (msg.author) {
|
// if (msg.author) {
|
||||||
const msgGroupContact = await wbot.getContactById(msg.from);
|
// const msgGroupContact = await wbot.getContactById(msg.from);
|
||||||
groupContact = await verifyGroup(msgGroupContact);
|
// groupContact = await verifyGroup(msgGroupContact);
|
||||||
}
|
// }
|
||||||
|
|
||||||
const profilePicUrl = await msgContact.getProfilePicUrl();
|
// const profilePicUrl = await msgContact.getProfilePicUrl();
|
||||||
const contact = await verifyContact(msgContact, profilePicUrl);
|
// const contact = await verifyContact(msgContact, profilePicUrl);
|
||||||
const ticket = await verifyTicket(contact, whatsappId, groupContact);
|
// const ticket = await verifyTicket(contact, whatsappId, groupContact);
|
||||||
|
|
||||||
await handleMessage(msg, ticket, contact);
|
// await handleMessage(msg, ticket, contact);
|
||||||
} catch (err) {
|
// } catch (err) {
|
||||||
Sentry.captureException(err);
|
// Sentry.captureException(err);
|
||||||
console.log(err);
|
// console.log(err);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
wbot.on("message_ack", async (msg, ack) => {
|
wbot.on("message_ack", async (msg, ack) => {
|
||||||
await new Promise(r => setTimeout(r, 500));
|
await new Promise(r => setTimeout(r, 500));
|
||||||
|
|||||||
Reference in New Issue
Block a user