mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
fix: unread messages count no working when fast reply
This commit is contained in:
@@ -42,6 +42,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
|
|
||||||
const ticket = await ShowTicketService(ticketId);
|
const ticket = await ShowTicketService(ticketId);
|
||||||
|
|
||||||
|
await SetTicketMessagesAsRead(ticket);
|
||||||
|
|
||||||
if (medias) {
|
if (medias) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
medias.map(async (media: Express.Multer.File) => {
|
medias.map(async (media: Express.Multer.File) => {
|
||||||
@@ -52,8 +54,6 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
await SendWhatsAppMessage({ body, ticket, quotedMsg });
|
await SendWhatsAppMessage({ body, ticket, quotedMsg });
|
||||||
}
|
}
|
||||||
|
|
||||||
await SetTicketMessagesAsRead(ticket);
|
|
||||||
|
|
||||||
return res.send();
|
return res.send();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ const SetTicketMessagesAsRead = async (ticket: Ticket): Promise<void> => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const wbot = await GetTicketWbot(ticket);
|
const wbot = await GetTicketWbot(ticket);
|
||||||
wbot.sendSeen(`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`);
|
await wbot.sendSeen(
|
||||||
|
`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Could not mark messages as read. Maybe whatsapp session disconnected? Err: ${err}`
|
`Could not mark messages as read. Maybe whatsapp session disconnected? Err: ${err}`
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ const FindOrCreateTicketService = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
ticket.update({ unreadMessages });
|
await ticket.update({ unreadMessages });
|
||||||
|
|
||||||
|
return ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ticket && groupContact) {
|
if (groupContact) {
|
||||||
ticket = await Ticket.findOne({
|
ticket = await Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
contactId: groupContact.id
|
contactId: groupContact.id
|
||||||
@@ -39,10 +41,10 @@ const FindOrCreateTicketService = async (
|
|||||||
userId: null,
|
userId: null,
|
||||||
unreadMessages
|
unreadMessages
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ticket && !groupContact) {
|
return ticket;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
ticket = await Ticket.findOne({
|
ticket = await Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
updatedAt: {
|
updatedAt: {
|
||||||
@@ -60,20 +62,20 @@ const FindOrCreateTicketService = async (
|
|||||||
userId: null,
|
userId: null,
|
||||||
unreadMessages
|
unreadMessages
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return ticket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ticket) {
|
const { id } = await Ticket.create({
|
||||||
const { id } = await Ticket.create({
|
contactId: groupContact ? groupContact.id : contact.id,
|
||||||
contactId: groupContact ? groupContact.id : contact.id,
|
status: "pending",
|
||||||
status: "pending",
|
isGroup: !!groupContact,
|
||||||
isGroup: !!groupContact,
|
unreadMessages,
|
||||||
unreadMessages,
|
whatsappId
|
||||||
whatsappId
|
});
|
||||||
});
|
|
||||||
|
|
||||||
ticket = await ShowTicketService(id);
|
ticket = await ShowTicketService(id);
|
||||||
}
|
|
||||||
|
|
||||||
return ticket;
|
return ticket;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user