diff --git a/backend/src/services/TicketServices/ListTicketsService.ts b/backend/src/services/TicketServices/ListTicketsService.ts index b616933..2959826 100644 --- a/backend/src/services/TicketServices/ListTicketsService.ts +++ b/backend/src/services/TicketServices/ListTicketsService.ts @@ -5,7 +5,7 @@ import Ticket from "../../models/Ticket"; import Contact from "../../models/Contact"; import Message from "../../models/Message"; import Queue from "../../models/Queue"; -// import ShowUserService from "../UserServices/ShowUserService"; +import ShowUserService from "../UserServices/ShowUserService"; interface Request { searchParam?: string; @@ -117,18 +117,14 @@ const ListTicketsService = async ({ } if (withUnreadMessages === "true") { - includeCondition = [ - ...includeCondition, - { - model: Message, - as: "messages", - attributes: [], - where: { - read: false, - fromMe: false - } - } - ]; + const user = await ShowUserService(userId); + const userQueueIds = user.queues.map(queue => queue.id); + + whereCondition = { + [Op.or]: [{ userId }, { status: "pending" }], + queueId: { [Op.or]: [userQueueIds, null] }, + unreadMessages: { [Op.gt]: 0 } + }; } const limit = 20; diff --git a/frontend/src/components/NotificationsPopOver/index.js b/frontend/src/components/NotificationsPopOver/index.js index 886e622..8925fe2 100644 --- a/frontend/src/components/NotificationsPopOver/index.js +++ b/frontend/src/components/NotificationsPopOver/index.js @@ -57,6 +57,8 @@ const NotificationsPopOver = () => { const [play] = useSound(alertSound); const soundAlertRef = useRef(); + const historyRef = useRef(history); + useEffect(() => { soundAlertRef.current = play; @@ -128,16 +130,16 @@ const NotificationsPopOver = () => { if (shouldNotNotificate) return; - handleNotifications(data, history); + handleNotifications(data); } }); return () => { socket.disconnect(); }; - }, [history, user]); + }, [user]); - const handleNotifications = (data, history) => { + const handleNotifications = data => { const { message, contact, ticket } = data; const options = { @@ -155,7 +157,7 @@ const NotificationsPopOver = () => { notification.onclick = e => { e.preventDefault(); window.focus(); - history.push(`/tickets/${ticket.id}`); + historyRef.current.push(`/tickets/${ticket.id}`); }; setDesktopNotifications(prevState => {