Skip to content

Commit 99ef74a

Browse files
authored
Merge pull request #6349 from WoltLab/6.2-remove-quote-dupplicate-button-click
Remove quotes that have already been inserted after clicking the button again
2 parents d558de1 + befba9e commit 99ef74a

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

ts/WoltLabSuite/Core/Component/Quote/Message.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import { wheneverFirstSeen } from "WoltLabSuite/Core/Helper/Selector";
1414
import { CKEditor } from "WoltLabSuite/Core/Component/Ckeditor";
1515
import {
1616
saveQuote,
17+
getFullQuoteUuid,
1718
saveFullQuote,
1819
markQuoteAsUsed,
1920
isFullQuoted,
2021
getKey,
22+
removeQuotes,
2123
} from "WoltLabSuite/Core/Component/Quote/Storage";
2224
import { promiseMutex } from "WoltLabSuite/Core/Helper/PromiseMutex";
2325
import { dispatchToCkeditor } from "WoltLabSuite/Core/Component/Ckeditor/Event";
@@ -96,6 +98,12 @@ export function registerContainer(
9698
promiseMutex(async (event: MouseEvent) => {
9799
event.preventDefault();
98100

101+
if (isFullQuoted(objectType, objectId)) {
102+
removeQuotes([getFullQuoteUuid(objectType, objectId)!]);
103+
quoteMessageButton!.classList.remove("active");
104+
return;
105+
}
106+
99107
const quoteMessage = await saveFullQuote(objectType, className, ~~container.dataset.objectId!);
100108
quoteMessageButton!.classList.add("active");
101109

ts/WoltLabSuite/Core/Component/Quote/Storage.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ function storeQuote(objectType: string, message: Message, quote: Quote): string
234234
return uuid;
235235
}
236236

237+
export function getFullQuoteUuid(objectType: string, objectId: number): string | undefined {
238+
const storage = getStorage();
239+
const key = getKey(objectType, objectId);
240+
241+
for (const [uuid, q] of storage.quotes.get(key)!) {
242+
if (q.rawMessage !== undefined && q.message !== undefined) {
243+
return uuid;
244+
}
245+
}
246+
247+
return undefined;
248+
}
249+
237250
function getStorage(): StorageData {
238251
const data = window.localStorage.getItem(STORAGE_KEY);
239252

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/Message.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/Storage.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)