mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
fix: unreadMessages not showing on notifications popover after refresh
This commit is contained in:
@@ -5,7 +5,7 @@ import Ticket from "../../models/Ticket";
|
|||||||
import Contact from "../../models/Contact";
|
import Contact from "../../models/Contact";
|
||||||
import Message from "../../models/Message";
|
import Message from "../../models/Message";
|
||||||
import Queue from "../../models/Queue";
|
import Queue from "../../models/Queue";
|
||||||
// import ShowUserService from "../UserServices/ShowUserService";
|
import ShowUserService from "../UserServices/ShowUserService";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
searchParam?: string;
|
searchParam?: string;
|
||||||
@@ -117,18 +117,14 @@ const ListTicketsService = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (withUnreadMessages === "true") {
|
if (withUnreadMessages === "true") {
|
||||||
includeCondition = [
|
const user = await ShowUserService(userId);
|
||||||
...includeCondition,
|
const userQueueIds = user.queues.map(queue => queue.id);
|
||||||
{
|
|
||||||
model: Message,
|
whereCondition = {
|
||||||
as: "messages",
|
[Op.or]: [{ userId }, { status: "pending" }],
|
||||||
attributes: [],
|
queueId: { [Op.or]: [userQueueIds, null] },
|
||||||
where: {
|
unreadMessages: { [Op.gt]: 0 }
|
||||||
read: false,
|
};
|
||||||
fromMe: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const limit = 20;
|
const limit = 20;
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ const NotificationsPopOver = () => {
|
|||||||
const [play] = useSound(alertSound);
|
const [play] = useSound(alertSound);
|
||||||
const soundAlertRef = useRef();
|
const soundAlertRef = useRef();
|
||||||
|
|
||||||
|
const historyRef = useRef(history);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
soundAlertRef.current = play;
|
soundAlertRef.current = play;
|
||||||
|
|
||||||
@@ -128,16 +130,16 @@ const NotificationsPopOver = () => {
|
|||||||
|
|
||||||
if (shouldNotNotificate) return;
|
if (shouldNotNotificate) return;
|
||||||
|
|
||||||
handleNotifications(data, history);
|
handleNotifications(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
};
|
};
|
||||||
}, [history, user]);
|
}, [user]);
|
||||||
|
|
||||||
const handleNotifications = (data, history) => {
|
const handleNotifications = data => {
|
||||||
const { message, contact, ticket } = data;
|
const { message, contact, ticket } = data;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
@@ -155,7 +157,7 @@ const NotificationsPopOver = () => {
|
|||||||
notification.onclick = e => {
|
notification.onclick = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
window.focus();
|
window.focus();
|
||||||
history.push(`/tickets/${ticket.id}`);
|
historyRef.current.push(`/tickets/${ticket.id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
setDesktopNotifications(prevState => {
|
setDesktopNotifications(prevState => {
|
||||||
|
|||||||
Reference in New Issue
Block a user