Update last read notification time when marking notification as read
authorCyperghost <olaf_schmitz_1@t-online.de>
Mon, 28 Oct 2024 11:38:06 +0000 (12:38 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Mon, 28 Oct 2024 11:38:06 +0000 (12:38 +0100)
ts/WoltLabSuite/Core/Notification/ServiceWorker.ts
ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js
wcfsetup/install/files/service-worker/index.php

index 5e52798d912e12a0537a413f5b2b0cac2ff94951..ba85f7381ed7e75b5e6e5f708fd6b9da5d4e2e67 100644 (file)
@@ -147,6 +147,6 @@ export function registerServiceWorker(): void {
   void _serviceWorker?.register();
 }
 
-export function updateLastNotificationTime(timestamp: number): void {
-  _serviceWorker?.updateLastNotificationTime(timestamp);
+export function updateLastNotificationTime(timestamp?: number): void {
+  _serviceWorker?.updateLastNotificationTime(timestamp ?? Math.round(Date.now() / 1000));
 }
index a59b978bb9d71dab7cced1095f872f143fcf8a5d..20a51e680a0bfcd0ac2e3e024dd36aa14bf4991d 100644 (file)
@@ -13,7 +13,7 @@ import { EventUpdateCounter, UserMenuButton, UserMenuData, UserMenuFooter, UserM
 import { registerProvider } from "../Manager";
 import * as Language from "../../../../Language";
 import { enableNotifications } from "../../../../Notification/Handler";
-import { registerServiceWorker } from "../../../../Notification/ServiceWorker";
+import { registerServiceWorker, updateLastNotificationTime } from "../../../../Notification/ServiceWorker";
 
 let originalFavicon = "";
 function setFaviconCounter(counter: number): void {
@@ -280,12 +280,14 @@ class UserMenuDataNotification implements DesktopNotifications, UserMenuProvider
     const response = (await dboAction("markAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction")
       .objectIds([objectId])
       .dispatch()) as ResponseMarkAsRead;
+    updateLastNotificationTime();
 
     this.updateCounter(response.totalCount);
   }
 
   async markAllAsRead(): Promise<void> {
     await dboAction("markAllAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction").dispatch();
+    updateLastNotificationTime();
 
     this.updateCounter(0);
   }
index 46af1c244e63d8228c28b96d0ad8763fc53d1fe9..9113f4c342d5369f63e6253835e302862be216dd 100644 (file)
@@ -128,6 +128,6 @@ define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend"], function (requi
         void _serviceWorker?.register();
     }
     function updateLastNotificationTime(timestamp) {
-        _serviceWorker?.updateLastNotificationTime(timestamp);
+        _serviceWorker?.updateLastNotificationTime(timestamp ?? Math.round(Date.now() / 1000));
     }
 });
index 7584edc599aa0fdcdd1e239030c715495cdc3cf8..b748337fb8262bcf22b2d803529669bd1291f080 100644 (file)
@@ -209,10 +209,12 @@ define(["require", "exports", "tslib", "../../../../Ajax", "../View", "../Manage
             const response = (await (0, Ajax_1.dboAction)("markAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction")
                 .objectIds([objectId])
                 .dispatch());
+            (0, ServiceWorker_1.updateLastNotificationTime)();
             this.updateCounter(response.totalCount);
         }
         async markAllAsRead() {
             await (0, Ajax_1.dboAction)("markAllAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction").dispatch();
+            (0, ServiceWorker_1.updateLastNotificationTime)();
             this.updateCounter(0);
         }
         updateCounter(count) {
index 8bfc6ecdbf3b5d9d5d24650fbd6a8bdc8a0e4e31..a92dc4a756bd6e2edb0f32c592f4c7810326678b 100644 (file)
@@ -125,7 +125,7 @@ function saveLastNotificationTimestamp(timestamp) {
       const storedTimestamp = getRequest.result;
 
       // Check if the new timestamp is greater than the stored timestamp
-      if (storedTimestamp === undefined || newTimestamp > storedTimestamp) {
+      if (storedTimestamp === undefined || timestamp > storedTimestamp) {
         store.put(timestamp, 'lastNotification');
       }
     };