From: Cyperghost Date: Mon, 28 Oct 2024 11:49:26 +0000 (+0100) Subject: Reformat code X-Git-Tag: 6.1.0~3^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=178191a5ab20acb95a61e299a9a8c8eb8d8e62dc;p=GitHub%2FWoltLab%2FWCF.git Reformat code --- diff --git a/wcfsetup/install/files/service-worker/index.php b/wcfsetup/install/files/service-worker/index.php index 034c1a52f8..b3232835b5 100644 --- a/wcfsetup/install/files/service-worker/index.php +++ b/wcfsetup/install/files/service-worker/index.php @@ -19,28 +19,30 @@ self.addEventListener("push", (event) => { const payload = event.data.json(); - getLastNotificationTimestamp().then(lastNotificationTimestamp => { - if (!lastNotificationTimestamp || payload.time < lastNotificationTimestamp) { - return; - } - - event.waitUntil( - removeOldNotifications(payload.notificationID, payload.time).then(() => - self.registration.showNotification(payload.title, { - body: payload.message, - icon: payload.icon, - timestamp: payload.time * 1000, - tag: payload.notificationID, - data: { - url: payload.url, - time: payload.time, - }, - }), - ).then(() => { - sendToClients(payload); - }), - ); - }); + getLastNotificationTimestamp().then((lastNotificationTimestamp) => { + if (!lastNotificationTimestamp || payload.time < lastNotificationTimestamp) { + return; + } + + event.waitUntil( + removeOldNotifications(payload.notificationID, payload.time) + .then(() => + self.registration.showNotification(payload.title, { + body: payload.message, + icon: payload.icon, + timestamp: payload.time * 1000, + tag: payload.notificationID, + data: { + url: payload.url, + time: payload.time, + }, + }), + ) + .then(() => { + sendToClients(payload); + }), + ); + }); }); self.addEventListener("notificationclick", (event) => { @@ -49,13 +51,13 @@ self.addEventListener("notificationclick", (event) => { event.waitUntil(self.clients.openWindow(event.notification.data.url)); }); -self.addEventListener('message', event => { - if (event.data && event.data.type === 'SAVE_LAST_NOTIFICATION_TIMESTAMP') { - saveLastNotificationTimestamp(event.data.timestamp); - } +self.addEventListener("message", (event) => { + if (event.data && event.data.type === "SAVE_LAST_NOTIFICATION_TIMESTAMP") { + saveLastNotificationTimestamp(event.data.timestamp); + } }); -async function sendToClients(payload){ +async function sendToClients(payload) { const allClients = await self.clients.matchAll({ includeUncontrolled: true, type: "window", @@ -87,72 +89,74 @@ async function removeOldNotifications(notificationID, time) { * IndexedDB functions to store the last notification timestamp. */ function openDatabase() { - return new Promise((resolve, reject) => { - const request = indexedDB.open('WOLTLAB_SUITE_CORE', 1); - - request.onupgradeneeded = (event) => { - const db = event.target.result; - if (!db.objectStoreNames.contains('notifications')) { - db.createObjectStore('notifications'); - } - }; - - request.onsuccess = (event) => { - resolve(event.target.result); - - if (!db.objectStoreNames.contains('notifications')) { - db.createObjectStore('notifications'); - } - }; - - request.onerror = (event) => { - reject('Database error: ' + event.target.errorCode); - }; - }); + return new Promise((resolve, reject) => { + const request = indexedDB.open("WOLTLAB_SUITE_CORE", 1); + + request.onupgradeneeded = (event) => { + const db = event.target.result; + if (!db.objectStoreNames.contains("notifications")) { + db.createObjectStore("notifications"); + } + }; + + request.onsuccess = (event) => { + resolve(event.target.result); + + if (!db.objectStoreNames.contains("notifications")) { + db.createObjectStore("notifications"); + } + }; + + request.onerror = (event) => { + reject("Database error: " + event.target.errorCode); + }; + }); } function saveLastNotificationTimestamp(timestamp) { - if (!timestamp || timestamp <= 0) { - return; - } - - openDatabase().then(db => { - const tx = db.transaction('notifications', 'readwrite'); - const store = tx.objectStore('notifications'); - const getRequest = store.get('lastNotification'); - - getRequest.onsuccess = () => { - const storedTimestamp = getRequest.result; - - // Check if the new timestamp is greater than the stored timestamp - if (storedTimestamp === undefined || timestamp > storedTimestamp) { - store.put(timestamp, 'lastNotification'); - } - }; - - getRequest.onerror = () => { - console.error('Failed to retrieve timestamp', getRequest.error); - }; - - tx.onerror = () => { - console.error('Transaction error', tx.error); - }; - }).catch(err => console.error('Failed to open database', err)); + if (!timestamp || timestamp <= 0) { + return; + } + + openDatabase() + .then((db) => { + const tx = db.transaction("notifications", "readwrite"); + const store = tx.objectStore("notifications"); + const getRequest = store.get("lastNotification"); + + getRequest.onsuccess = () => { + const storedTimestamp = getRequest.result; + + // Check if the new timestamp is greater than the stored timestamp + if (storedTimestamp === undefined || timestamp > storedTimestamp) { + store.put(timestamp, "lastNotification"); + } + }; + + getRequest.onerror = () => { + console.error("Failed to retrieve timestamp", getRequest.error); + }; + + tx.onerror = () => { + console.error("Transaction error", tx.error); + }; + }) + .catch((err) => console.error("Failed to open database", err)); } function getLastNotificationTimestamp() { - return openDatabase().then(db => { - return new Promise((resolve, reject) => { - const tx = db.transaction('notifications', 'readonly'); - const store = tx.objectStore('notifications'); - const request = store.get('lastNotification'); - - request.onsuccess = () => { - resolve(request.result); - }; - request.onerror = () => { - reject('Failed to retrieve timestamp'); - }; - }); - }); + return openDatabase().then((db) => { + return new Promise((resolve, reject) => { + const tx = db.transaction("notifications", "readonly"); + const store = tx.objectStore("notifications"); + const request = store.get("lastNotification"); + + request.onsuccess = () => { + resolve(request.result); + }; + request.onerror = () => { + reject("Failed to retrieve timestamp"); + }; + }); + }); }