v0.2.9
RustBox CI / rustbox (push) Canceled after 0s

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-01 21:36:04 +01:00
1 parent dacdf9c27d
commit a116890e20
34 files changed
+186 -83

No files matched your search

+51 -1
View File
@@ -219,6 +219,54 @@ function newMailNotificationKey(data, accountId) {
return `${accountId || ""}|${data?.folder || "INBOX"}|${data?.latest_sender || ""}|${data?.latest_subject || ""}|${data?.count || 1}`;
}
function realtimeNotificationSuppressionKey(folder, accountId = state.accountId) {
return `${accountId || ""}|${folder || "INBOX"}`;
}
function suppressRealtimeNotificationsForFolder(folder, accountId = state.accountId) {
if (!folder) return () => { };
const key = realtimeNotificationSuppressionKey(folder, accountId);
state.realtimeNotificationSuppressions.set(key, (state.realtimeNotificationSuppressions.get(key) || 0) + 1);
let released = false;
return () => {
if (released) return;
released = true;
setTimeout(() => {
const count = state.realtimeNotificationSuppressions.get(key) || 0;
if (count <= 1) state.realtimeNotificationSuppressions.delete(key);
else state.realtimeNotificationSuppressions.set(key, count - 1);
}, 2500);
};
}
function realtimeNewMailNotificationsSuppressed(data, accountId) {
if (!state.realtimeNotificationsReady) return true;
return (state.realtimeNotificationSuppressions.get(realtimeNotificationSuppressionKey(data?.folder, accountId)) || 0) > 0;
}
function scheduleRealtimeNotificationsReady() {
if (!state.realtimeNotificationsArmRequested || state.realtimeNotificationsReady) return;
clearTimeout(state.realtimeNotificationsReadyTimer);
state.realtimeNotificationsReadyTimer = setTimeout(() => {
state.realtimeNotificationsReadyTimer = null;
state.realtimeNotificationsReady = true;
}, 3000);
}
function armRealtimeNotifications() {
state.realtimeNotificationsArmRequested = true;
if (state.ws?.readyState === WebSocket.OPEN) scheduleRealtimeNotificationsReady();
}
function resetRealtimeNotificationGate() {
clearTimeout(state.realtimeNotificationsReadyTimer);
state.realtimeNotificationsReadyTimer = null;
state.realtimeNotificationsReady = false;
state.realtimeNotificationsArmRequested = false;
state.realtimeNotificationSuppressions.clear();
state.realtimeNotifiedMessages.clear();
}
function isDuplicateNewMailNotification(data, accountId) {
const now = Date.now();
for (const [key, seenAt] of state.realtimeNotifiedMessages) {
@@ -455,6 +503,7 @@ function connectRealtime() {
state.realtimeWatchedFolder = null;
startRealtimeWatchdog(socket);
syncRealtimeWatchedFolder(true);
scheduleRealtimeNotificationsReady();
if (reconnect) void resyncRealtimeState();
};
socket.onmessage = (message) => {
@@ -470,7 +519,8 @@ function connectRealtime() {
const event = payload.event || {};
if (event.type === "NewMessages") {
const data = event.data || {};
if (!isDuplicateNewMailNotification(data, payload.accountId)) {
const duplicate = isDuplicateNewMailNotification(data, payload.accountId);
if (!duplicate && !realtimeNewMailNotificationsSuppressed(data, payload.accountId)) {
toastNewMail(data, payload.accountId);
notifyNewMail(data, payload.accountId);
}