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