--- /dev/null
+/**
+ * Requests render a full quote of a message.
+ *
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.2
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.messageAuthor = messageAuthor;
+ async function messageAuthor(className, objectID) {
+ const url = new URL(window.WSC_RPC_API_URL + "core/messages/messageauthor");
+ url.searchParams.set("className", className);
+ url.searchParams.set("objectID", objectID.toString());
+ let response;
+ try {
+ response = (await (0, Backend_1.prepareRequest)(url).get().allowCaching().fetchAsJson());
+ }
+ catch (e) {
+ return (0, Result_1.apiResultFromError)(e);
+ }
+ return (0, Result_1.apiResultFromValue)(response);
+ }
+});
--- /dev/null
+/**
+ * Requests render a full quote of a message.
+ *
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.2
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.renderQuote = renderQuote;
+ async function renderQuote(objectType, className, objectID) {
+ const url = new URL(window.WSC_RPC_API_URL + "core/messages/renderquote");
+ url.searchParams.set("objectType", objectType);
+ url.searchParams.set("className", className);
+ url.searchParams.set("fullQuote", "true");
+ url.searchParams.set("objectID", objectID.toString());
+ let response;
+ try {
+ response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson());
+ }
+ catch (e) {
+ return (0, Result_1.apiResultFromError)(e);
+ }
+ return (0, Result_1.apiResultFromValue)(response);
+ }
+});
--- /dev/null
+/**
+ * Stores the quote data.
+ *
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.2
+ * @woltlabExcludeBundle tiny
+ */
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Core", "WoltLabSuite/Core/Api/Messages/RenderQuote", "WoltLabSuite/Core/Api/Messages/Author", "WoltLabSuite/Core/Component/Quote/List"], function (require, exports, tslib_1, Core, RenderQuote_1, Author_1, List_1) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.saveQuote = saveQuote;
+ exports.saveFullQuote = saveFullQuote;
+ exports.getQuotes = getQuotes;
+ exports.getMessage = getMessage;
+ Core = tslib_1.__importStar(Core);
+ const STORAGE_KEY = Core.getStoragePrefix() + "quotes";
+ async function saveQuote(objectType, objectId, objectClassName, message) {
+ const result = await (0, Author_1.messageAuthor)(objectClassName, objectId);
+ if (!result.ok) {
+ // TODO error handling
+ return;
+ }
+ storeQuote(objectType, result.value, message);
+ (0, List_1.refreshQuoteLists)();
+ }
+ async function saveFullQuote(objectType, objectClassName, objectId) {
+ const result = await (0, RenderQuote_1.renderQuote)(objectType, objectClassName, objectId);
+ if (!result.ok) {
+ // TODO error handling
+ return;
+ }
+ storeQuote(objectType, {
+ objectID: result.value.objectID,
+ time: result.value.time,
+ title: result.value.title,
+ link: result.value.link,
+ authorID: result.value.authorID,
+ author: result.value.author,
+ avatar: result.value.avatar,
+ }, result.value.message);
+ }
+ function storeQuote(objectType, message, quote) {
+ const storage = getStorage();
+ const key = getKey(objectType, message.objectID);
+ if (!storage.quotes.has(key)) {
+ storage.quotes.set(key, new Set());
+ }
+ storage.messages.set(key, message);
+ 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) {
+ return {
+ quotes: new Map(),
+ messages: new Map(),
+ };
+ }
+ else {
+ return JSON.parse(data, (key, value) => {
+ if (key === "quotes") {
+ const result = new Map(value);
+ for (const [key, setValue] of result) {
+ result.set(key, new Set(setValue));
+ }
+ return result;
+ }
+ else if (key === "messages") {
+ return new Map(value);
+ }
+ return value;
+ });
+ }
+ }
+ function getKey(objectType, objectId) {
+ return `${objectType}:${objectId}`;
+ }
+ function saveStorage(data) {
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify(data, (key, value) => {
+ if (value instanceof Map) {
+ return Array.from(value.entries());
+ }
+ else if (value instanceof Set) {
+ return Array.from(value);
+ }
+ return value;
+ }));
+ }
+});