fix: clean last notifications when visible = true

This commit is contained in:
canove
2020-07-30 11:26:39 -03:00
parent f03f8d52b7
commit 940844c91f

View File

@@ -317,16 +317,24 @@ const TicketsList = () => {
const options = { const options = {
body: `${data.message.body} - ${format(new Date(), "HH:mm")}`, body: `${data.message.body} - ${format(new Date(), "HH:mm")}`,
icon: data.contact.profilePicUrl, icon: data.contact.profilePicUrl,
tag: data.ticket.id,
}; };
let notification = new Notification( let notification = new Notification(
`Mensagem de ${data.contact.name}`, `Mensagem de ${data.contact.name}`,
options options
); );
notification.onclick = function (event) { notification.onclick = function (event) {
event.preventDefault(); // event.preventDefault(); //
window.open(`/chat/${data.ticket.id}`, "_self"); window.open(`/chat/${data.ticket.id}`, "_self");
}; };
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
notification.close();
}
});
document.getElementById("sound").play(); document.getElementById("sound").play();
}; };