Improve the consistency of property/function names
authorAlexander Ebert <ebert@woltlab.com>
Mon, 28 Oct 2024 13:32:03 +0000 (14:32 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 28 Oct 2024 13:32:03 +0000 (14:32 +0100)
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
ts/WoltLabSuite/Core/BootstrapFrontend.ts
ts/WoltLabSuite/Core/Notification/ServiceWorker.ts
ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts
wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js
wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php
wcfsetup/install/files/service-worker/index.php

index d587217e645b82b763410ba4c1a30a93e3c58472..a607acfb5e11d2a95cc0d0cbd01c1834a2540a2d 100644 (file)
@@ -82,7 +82,7 @@ window.addEventListener('pageshow', function(event) {
                                publicKey: '{@SERVICE_WORKER_PUBLIC_KEY|encodeJS}',
                                serviceWorkerJsUrl: '{$__wcf->getPath('wcf')}service-worker/',
                                registerUrl: '{link controller="RegisterServiceWorker"}{/link}',
-                               lastReadNotification: {$__wcf->getUserNotificationHandler()->getLastReadNotificationTime()}
+                               notificationLastReadTime: {$__wcf->getUserNotificationHandler()->getTimeOfLastReadNotification()}
                        },
                        {/if}
                        dynamicColorScheme: {if $__wcf->getStyleHandler()->getColorScheme() === 'system'}true{else}false{/if},
index 3e8ae0d61fc8e4b9e515b6d1ad46527eea7ff877..e23ec7592ce60996886d75dad79ba180fd83d292 100644 (file)
@@ -29,7 +29,7 @@ interface BootstrapOptions {
     publicKey: string;
     serviceWorkerJsUrl: string;
     registerUrl: string;
-    lastReadNotification: number;
+    notificationLastReadTime: number;
   };
   dynamicColorScheme: boolean;
   endpointUserPopover: string;
@@ -115,7 +115,7 @@ export function setup(options: BootstrapOptions): void {
         options.serviceWorker.publicKey,
         options.serviceWorker.serviceWorkerJsUrl,
         options.serviceWorker.registerUrl,
-        options.serviceWorker.lastReadNotification,
+        options.serviceWorker.notificationLastReadTime,
       );
     }
   }
index ba85f7381ed7e75b5e6e5f708fd6b9da5d4e2e67..d24b8136c3f0b085978fa878184e627202c4962a 100644 (file)
@@ -96,10 +96,10 @@ class ServiceWorker {
     return outputArray;
   }
 
-  public updateLastNotificationTime(timestamp: number): void {
+  public updateNotificationLastReadTime(timestamp: number): void {
     window.navigator.serviceWorker.controller?.postMessage({
-      type: "SAVE_LAST_NOTIFICATION_TIMESTAMP",
-      timestamp: timestamp,
+      type: "UPDATE_NOTIFICATION_LAST_READ_TIME",
+      timestamp,
     });
   }
 }
@@ -131,7 +131,7 @@ export function setup(
   publicKey: string,
   serviceWorkerJsUrl: string,
   registerUrl: string,
-  lastReadNotification: number,
+  notificationLastReadTime: number,
 ): void {
   if (!serviceWorkerSupported()) {
     return;
@@ -139,7 +139,7 @@ export function setup(
   _serviceWorker = new ServiceWorker(publicKey, serviceWorkerJsUrl, registerUrl);
   if (Notification.permission === "granted") {
     registerServiceWorker();
-    _serviceWorker.updateLastNotificationTime(lastReadNotification);
+    _serviceWorker.updateNotificationLastReadTime(notificationLastReadTime);
   }
 }
 
@@ -147,6 +147,6 @@ export function registerServiceWorker(): void {
   void _serviceWorker?.register();
 }
 
-export function updateLastNotificationTime(timestamp?: number): void {
-  _serviceWorker?.updateLastNotificationTime(timestamp ?? Math.round(Date.now() / 1000));
+export function updateNotificationLastReadTime(timestamp?: number): void {
+  _serviceWorker?.updateNotificationLastReadTime(timestamp ?? Math.round(Date.now() / 1000));
 }
index 20a51e680a0bfcd0ac2e3e024dd36aa14bf4991d..d4dcd5119db2f3bb7688af7dd5fef430b792c23e 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, updateLastNotificationTime } from "../../../../Notification/ServiceWorker";
+import { registerServiceWorker, updateNotificationLastReadTime } from "../../../../Notification/ServiceWorker";
 
 let originalFavicon = "";
 function setFaviconCounter(counter: number): void {
@@ -280,14 +280,14 @@ class UserMenuDataNotification implements DesktopNotifications, UserMenuProvider
     const response = (await dboAction("markAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction")
       .objectIds([objectId])
       .dispatch()) as ResponseMarkAsRead;
-    updateLastNotificationTime();
+    updateNotificationLastReadTime();
 
     this.updateCounter(response.totalCount);
   }
 
   async markAllAsRead(): Promise<void> {
     await dboAction("markAllAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction").dispatch();
-    updateLastNotificationTime();
+    updateNotificationLastReadTime();
 
     this.updateCounter(0);
   }
index e5eafebf94b891d685eeb640d454d632396b5f10..e0b503eabca515ac616635f898b62aa0cff3f99e 100644 (file)
@@ -78,7 +78,7 @@ define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Ui
         if (User_1.default.userId) {
             UiFeedDialog.setup();
             if (options.serviceWorker) {
-                (0, ServiceWorker_1.setup)(options.serviceWorker.publicKey, options.serviceWorker.serviceWorkerJsUrl, options.serviceWorker.registerUrl, options.serviceWorker.lastReadNotification);
+                (0, ServiceWorker_1.setup)(options.serviceWorker.publicKey, options.serviceWorker.serviceWorkerJsUrl, options.serviceWorker.registerUrl, options.serviceWorker.notificationLastReadTime);
             }
         }
         (0, LazyLoader_1.whenFirstSeen)("woltlab-core-reaction-summary", () => {
index 9113f4c342d5369f63e6253835e302862be216dd..80f54f4ea4c63eefa6bd7e403f03a00ed87696f4 100644 (file)
@@ -11,7 +11,7 @@ define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend"], function (requi
     exports.serviceWorkerSupported = serviceWorkerSupported;
     exports.setup = setup;
     exports.registerServiceWorker = registerServiceWorker;
-    exports.updateLastNotificationTime = updateLastNotificationTime;
+    exports.updateNotificationLastReadTime = updateNotificationLastReadTime;
     let _serviceWorker = null;
     class ServiceWorker {
         #publicKey;
@@ -88,10 +88,10 @@ define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend"], function (requi
             }
             return outputArray;
         }
-        updateLastNotificationTime(timestamp) {
+        updateNotificationLastReadTime(timestamp) {
             window.navigator.serviceWorker.controller?.postMessage({
-                type: "SAVE_LAST_NOTIFICATION_TIMESTAMP",
-                timestamp: timestamp,
+                type: "UPDATE_NOTIFICATION_LAST_READ_TIME",
+                timestamp,
             });
         }
     }
@@ -114,20 +114,20 @@ define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend"], function (requi
         }
         return true;
     }
-    function setup(publicKey, serviceWorkerJsUrl, registerUrl, lastReadNotification) {
+    function setup(publicKey, serviceWorkerJsUrl, registerUrl, notificationLastReadTime) {
         if (!serviceWorkerSupported()) {
             return;
         }
         _serviceWorker = new ServiceWorker(publicKey, serviceWorkerJsUrl, registerUrl);
         if (Notification.permission === "granted") {
             registerServiceWorker();
-            _serviceWorker.updateLastNotificationTime(lastReadNotification);
+            _serviceWorker.updateNotificationLastReadTime(notificationLastReadTime);
         }
     }
     function registerServiceWorker() {
         void _serviceWorker?.register();
     }
-    function updateLastNotificationTime(timestamp) {
-        _serviceWorker?.updateLastNotificationTime(timestamp ?? Math.round(Date.now() / 1000));
+    function updateNotificationLastReadTime(timestamp) {
+        _serviceWorker?.updateNotificationLastReadTime(timestamp ?? Math.round(Date.now() / 1000));
     }
 });
index b748337fb8262bcf22b2d803529669bd1291f080..c077e3cc1c148e445dff4c7825ab0467eed68f2c 100644 (file)
@@ -209,12 +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)();
+            (0, ServiceWorker_1.updateNotificationLastReadTime)();
             this.updateCounter(response.totalCount);
         }
         async markAllAsRead() {
             await (0, Ajax_1.dboAction)("markAllAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction").dispatch();
-            (0, ServiceWorker_1.updateLastNotificationTime)();
+            (0, ServiceWorker_1.updateNotificationLastReadTime)();
             this.updateCounter(0);
         }
         updateCounter(count) {
index f5b7fae90efd73b1eab6a0a7b7e5356abf193f2c..926aa9d6a010363ff561e8e1a58ccdbf4dc37376 100644 (file)
@@ -1101,12 +1101,10 @@ class UserNotificationHandler extends SingletonFactory
     }
 
     /**
-     * Returns the timestamp of the last read notification for the active user.
-     * Or `0` if no notification has been read yet.
-     *
-     * @return  int
+     * Returns the timestamp of the last read notification for the active user
+     * or `0` if no notification has been read yet.
      */
-    public function getLastReadNotificationTime(): int
+    public function getTimeOfLastReadNotification(): int
     {
         $sql = "SELECT MAX(confirmTime)
                 FROM   wcf1_user_notification
index 26a97172e91a0bdc6c83e5a6b3bc0fdbd0072a8c..369c225afd7cde54a4f0fbabb536271d8585a190 100644 (file)
@@ -2,11 +2,11 @@
 
 @\header('Service-Worker-Allowed: /');
 @\header('Content-Type: text/javascript; charset=utf-8');
-?>
-/**
+?>/**
  * @author      Olaf Braun
  * @copyright   2001-2024 WoltLab GmbH
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since              6.1
  */
 
 self.addEventListener("push", (event) => {
@@ -19,8 +19,8 @@ self.addEventListener("push", (event) => {
 
        const payload = event.data.json();
 
-       getLastNotificationTimestamp().then((lastNotificationTimestamp) => {
-               if (lastNotificationTimestamp && payload.time < lastNotificationTimestamp) {
+       getTimeOfLastReadNotification().then((notificationLastReadTime) => {
+               if (notificationLastReadTime && payload.time < notificationLastReadTime) {
                        return;
                }
 
@@ -52,8 +52,8 @@ self.addEventListener("notificationclick", (event) => {
 });
 
 self.addEventListener("message", (event) => {
-       if (event.data && event.data.type === "SAVE_LAST_NOTIFICATION_TIMESTAMP") {
-               saveLastNotificationTimestamp(event.data.timestamp);
+       if (event.data && event.data.type === "UPDATE_NOTIFICATION_LAST_READ_TIME") {
+               updateNotificationLastReadTime(event.data.timestamp);
        }
 });
 
@@ -105,12 +105,12 @@ function openDatabase() {
                };
 
                request.onerror = (event) => {
-                       reject("Database error: %s", event.target.errorCode);
+                       reject(new Error(`Database error: ${event.target.errorCode}`));
                };
        });
 }
 
-function saveLastNotificationTimestamp(timestamp) {
+function updateNotificationLastReadTime(timestamp) {
        if (!timestamp || timestamp <= 0) {
                return;
        }
@@ -141,7 +141,7 @@ function saveLastNotificationTimestamp(timestamp) {
                .catch((err) => console.error("Failed to open database: %s", err));
 }
 
-function getLastNotificationTimestamp() {
+function getTimeOfLastReadNotification() {
        return openDatabase().then((db) => {
                return new Promise((resolve, reject) => {
                        const tx = db.transaction("notifications", "readonly");
@@ -152,7 +152,7 @@ function getLastNotificationTimestamp() {
                                resolve(request.result);
                        };
                        request.onerror = () => {
-                               reject("Failed to retrieve timestamp");
+                               reject(new Error("Failed to retrieve timestamp"));
                        };
                });
        });