Keep admin alerts until unread chats are opened
This commit is contained in:
+27
-4
@@ -94,9 +94,9 @@ $("#settingsForm").brandHex.addEventListener("input", (event) => {
|
|||||||
if (color) $("#settingsForm").brand.value = color;
|
if (color) $("#settingsForm").brand.value = color;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("focus", stopAttention);
|
window.addEventListener("focus", syncAttentionWithUnread);
|
||||||
document.addEventListener("visibilitychange", () => {
|
document.addEventListener("visibilitychange", () => {
|
||||||
if (!document.hidden) stopAttention();
|
if (!document.hidden) syncAttentionWithUnread();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#onlineToggle").addEventListener("change", async () => {
|
$("#onlineToggle").addEventListener("change", async () => {
|
||||||
@@ -302,6 +302,7 @@ async function loadConversations() {
|
|||||||
state.conversations = data.conversations;
|
state.conversations = data.conversations;
|
||||||
syncConversationVisitors();
|
syncConversationVisitors();
|
||||||
renderConversations();
|
renderConversations();
|
||||||
|
syncAttentionWithUnread();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadVisitors() {
|
async function loadVisitors() {
|
||||||
@@ -314,7 +315,6 @@ async function loadVisitors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function openConversation(id) {
|
async function openConversation(id) {
|
||||||
stopAttention();
|
|
||||||
state.activeId = id;
|
state.activeId = id;
|
||||||
const data = await api(`/api/admin/conversations/${id}`);
|
const data = await api(`/api/admin/conversations/${id}`);
|
||||||
state.active = data;
|
state.active = data;
|
||||||
@@ -323,6 +323,7 @@ async function openConversation(id) {
|
|||||||
syncConversationVisitors();
|
syncConversationVisitors();
|
||||||
renderConversations();
|
renderConversations();
|
||||||
renderActive();
|
renderActive();
|
||||||
|
syncAttentionWithUnread();
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectEvents() {
|
function connectEvents() {
|
||||||
@@ -345,13 +346,17 @@ function connectEvents() {
|
|||||||
renderVisitors();
|
renderVisitors();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const visitorMessage = isVisitorMessageEvent(data);
|
||||||
|
const eventConversationId = eventConversationIdFrom(data);
|
||||||
|
const shouldNotify = data.type === "conversation:new" || (visitorMessage && eventConversationId !== state.activeId);
|
||||||
await loadConversations();
|
await loadConversations();
|
||||||
if (data.type === "conversation:delete" && data.conversationId === state.activeId) {
|
if (data.type === "conversation:delete" && data.conversationId === state.activeId) {
|
||||||
clearActiveConversation();
|
clearActiveConversation();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state.activeId) await openConversation(state.activeId).catch(() => clearActiveConversation());
|
if (state.activeId) await openConversation(state.activeId).catch(() => clearActiveConversation());
|
||||||
if (data.type === "conversation:new" || isVisitorMessageEvent(data)) notify();
|
if (shouldNotify) notify();
|
||||||
|
else syncAttentionWithUnread();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,6 +652,7 @@ function clearActiveConversation() {
|
|||||||
`;
|
`;
|
||||||
$("#messages").innerHTML = "";
|
$("#messages").innerHTML = "";
|
||||||
$("#replyForm").classList.add("hidden");
|
$("#replyForm").classList.add("hidden");
|
||||||
|
syncAttentionWithUnread();
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderAttachments(attachments) {
|
function renderAttachments(attachments) {
|
||||||
@@ -888,6 +894,19 @@ function stopRepeatingSound() {
|
|||||||
state.soundRepeatTimer = null;
|
state.soundRepeatTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasUnreadConversations() {
|
||||||
|
return state.conversations.some((conversation) => conversation.hasUnread && conversation.id !== state.activeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncAttentionWithUnread() {
|
||||||
|
if (hasUnreadConversations()) {
|
||||||
|
startAttention();
|
||||||
|
startRepeatingSound();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stopAttention();
|
||||||
|
}
|
||||||
|
|
||||||
function soundPattern(style) {
|
function soundPattern(style) {
|
||||||
const patterns = {
|
const patterns = {
|
||||||
tap: [
|
tap: [
|
||||||
@@ -951,6 +970,10 @@ function isVisitorMessageEvent(data) {
|
|||||||
return messages[messages.length - 1]?.senderType === "visitor";
|
return messages[messages.length - 1]?.senderType === "visitor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function eventConversationIdFrom(data) {
|
||||||
|
return data.conversationId || data.conversation?.id || data.payload?.conversation?.id || null;
|
||||||
|
}
|
||||||
|
|
||||||
function flashTyping() {
|
function flashTyping() {
|
||||||
$("#typingNotice").classList.remove("hidden");
|
$("#typingNotice").classList.remove("hidden");
|
||||||
clearTimeout(flashTyping.timer);
|
clearTimeout(flashTyping.timer);
|
||||||
|
|||||||
Reference in New Issue
Block a user