From 5835bd869a4d4feadac7908fad290e1af77a7312 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Mon, 28 Oct 2024 12:38:06 +0100 Subject: [PATCH] Update last read notification time when marking notification as read --- ts/WoltLabSuite/Core/Notification/ServiceWorker.ts | 4 ++-- ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts | 4 +++- .../files/js/WoltLabSuite/Core/Notification/ServiceWorker.js | 2 +- .../js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js | 2 ++ wcfsetup/install/files/service-worker/index.php | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts b/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts index 5e52798d91..ba85f7381e 100644 --- a/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts +++ b/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts @@ -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)); } diff --git a/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts b/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts index a59b978bb9..20a51e680a 100644 --- a/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts +++ b/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts @@ -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 { await dboAction("markAllAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction").dispatch(); + updateLastNotificationTime(); this.updateCounter(0); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js index 46af1c244e..9113f4c342 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js @@ -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)); } }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js index 7584edc599..b748337fb8 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js @@ -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) { diff --git a/wcfsetup/install/files/service-worker/index.php b/wcfsetup/install/files/service-worker/index.php index 8bfc6ecdbf..a92dc4a756 100644 --- a/wcfsetup/install/files/service-worker/index.php +++ b/wcfsetup/install/files/service-worker/index.php @@ -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'); } }; -- 2.20.1