From 126bcda9a8e115e1ddd5bd6096247bcfab859d43 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 19 Dec 2024 13:11:05 +0100 Subject: [PATCH] Add function to remove quotes --- .../Core/Component/Quote/Storage.ts | 40 ++++++++++++++----- .../Core/Component/Quote/Storage.js | 29 ++++++++++---- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/ts/WoltLabSuite/Core/Component/Quote/Storage.ts b/ts/WoltLabSuite/Core/Component/Quote/Storage.ts index 8c75371ddb..a4bdfbb545 100644 --- a/ts/WoltLabSuite/Core/Component/Quote/Storage.ts +++ b/ts/WoltLabSuite/Core/Component/Quote/Storage.ts @@ -64,6 +64,36 @@ export async function saveFullQuote(objectType: string, objectClassName: string, ); } +export function getQuotes(): Map> { + return getStorage().quotes; +} + +export function getMessage(objectType: string, objectId?: number): Message | undefined { + const key = objectId ? getKey(objectType, objectId) : objectType; + + return getStorage().messages.get(key); +} + +export function removeQuote(objectType: string, objectId: number, quote: string): void { + const storage = getStorage(); + + const key = getKey(objectType, objectId); + if (!storage.quotes.has(key)) { + return; + } + + storage.quotes.get(key)!.delete(quote); + + if (storage.quotes.get(key)!.size === 0) { + storage.quotes.delete(key); + storage.messages.delete(key); + } + + saveStorage(storage); + + refreshQuoteLists(); +} + function storeQuote(objectType: string, message: Message, quote: string): void { const storage = getStorage(); @@ -79,16 +109,6 @@ function storeQuote(objectType: string, message: Message, quote: string): void { saveStorage(storage); } -export function getQuotes(): Map> { - return getStorage().quotes; -} - -export function getMessage(objectType: string, objectId?: number): Message | undefined { - const key = objectId ? getKey(objectType, objectId) : objectType; - - return getStorage().messages.get(key); -} - function getStorage(): StorageData { const data = window.localStorage.getItem(STORAGE_KEY); if (data === null) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/Storage.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/Storage.js index 4de88f6177..fd6e14848d 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/Storage.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/Storage.js @@ -14,6 +14,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Core", "WoltLabSuite/C exports.saveFullQuote = saveFullQuote; exports.getQuotes = getQuotes; exports.getMessage = getMessage; + exports.removeQuote = removeQuote; Core = tslib_1.__importStar(Core); const STORAGE_KEY = Core.getStoragePrefix() + "quotes"; async function saveQuote(objectType, objectId, objectClassName, message) { @@ -41,6 +42,27 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Core", "WoltLabSuite/C avatar: result.value.avatar, }, result.value.message); } + function getQuotes() { + return getStorage().quotes; + } + function getMessage(objectType, objectId) { + const key = objectId ? getKey(objectType, objectId) : objectType; + return getStorage().messages.get(key); + } + function removeQuote(objectType, objectId, quote) { + const storage = getStorage(); + const key = getKey(objectType, objectId); + if (!storage.quotes.has(key)) { + return; + } + storage.quotes.get(key).delete(quote); + if (storage.quotes.get(key).size === 0) { + storage.quotes.delete(key); + storage.messages.delete(key); + } + saveStorage(storage); + (0, List_1.refreshQuoteLists)(); + } function storeQuote(objectType, message, quote) { const storage = getStorage(); const key = getKey(objectType, message.objectID); @@ -51,13 +73,6 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Core", "WoltLabSuite/C storage.quotes.get(key).add(quote); saveStorage(storage); } - function getQuotes() { - return getStorage().quotes; - } - function getMessage(objectType, objectId) { - const key = objectId ? getKey(objectType, objectId) : objectType; - return getStorage().messages.get(key); - } function getStorage() { const data = window.localStorage.getItem(STORAGE_KEY); if (data === null) { -- 2.20.1