Improve the collection of message meta data
authorAlexander Ebert <ebert@woltlab.com>
Thu, 6 Apr 2023 12:00:59 +0000 (14:00 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 6 Apr 2023 12:00:59 +0000 (14:00 +0200)
Fixes #5393

ts/WoltLabSuite/Core/Component/Ckeditor/Event.ts
ts/WoltLabSuite/Core/Ui/Message/InlineEditor.ts
ts/WoltLabSuite/Core/Ui/Message/Reply.ts
wcfsetup/install/files/js/WCF.Attachment.js
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Event.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/InlineEditor.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/Reply.js

index e92ebb69a1f9382fd0dcfc316842a7141fc78516..9663087b3e6c3a6297d057e74d159d8a4179112e 100644 (file)
@@ -16,6 +16,7 @@ import type { UploadMediaEventPayload } from "./Media";
 import type { InsertQuoteEventPayload } from "./Quote";
 
 const enum EventNames {
+  CollectMetaData = "ckeditor5:collect-meta-data",
   Destroy = "ckeditor5:destroy",
   DiscardRecoveredData = "ckeditor5:discard-recovered-data",
   InsertAttachment = "ckeditor5:insert-attachment",
@@ -29,7 +30,9 @@ const enum EventNames {
   UploadAttachment = "ckeditor5:upload-attachment",
   UploadMedia = "ckeditor5:upload-media",
 }
-
+type CollectMetaDataEventPayload = {
+  metaData: Record<string, unknown>;
+};
 type ReadyEventPayload = {
   ckeditor: CKEditor;
 };
@@ -55,6 +58,14 @@ class EventDispatcher {
     this.#element = element;
   }
 
+  collectMetaData(payload: CollectMetaDataEventPayload): void {
+    this.#element.dispatchEvent(
+      new CustomEvent<CollectMetaDataEventPayload>(EventNames.CollectMetaData, {
+        detail: payload,
+      }),
+    );
+  }
+
   destroy(): void {
     this.#element.dispatchEvent(new CustomEvent<void>(EventNames.Destroy));
   }
@@ -151,6 +162,14 @@ class EventListener {
     this.#element = element;
   }
 
+  collectMetaData(callback: (payload: CollectMetaDataEventPayload) => void): this {
+    this.#element.addEventListener(EventNames.CollectMetaData, (event: CustomEvent<CollectMetaDataEventPayload>) => {
+      callback(event.detail);
+    });
+
+    return this;
+  }
+
   destroy(callback: () => void): this {
     this.#element.addEventListener(EventNames.Destroy, () => {
       callback();
index 3e33fc6202aa73ce483b0ee772acc2c71fc20622..2e7626372ad1deec12d40ec16583213d4fd0bb5a 100644 (file)
@@ -6,6 +6,7 @@
  * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
 
+import { dispatchToCkeditor } from "WoltLabSuite/Core/Component/Ckeditor/Event";
 import * as Ajax from "../../Ajax";
 import { AjaxCallbackObject, AjaxCallbackSetup, ResponseData } from "../../Ajax/Data";
 import { getCkeditorById } from "../../Component/Ckeditor";
@@ -486,7 +487,7 @@ class UiMessageInlineEditor implements AjaxCallbackObject {
 
     (validateResult as Promise<void[]>).then(
       () => {
-        EventHandler.fire("com.woltlab.wcf.ckeditor5", `submit_${id}`, parameters);
+        dispatchToCkeditor(ckeditor.sourceElement).collectMetaData({ metaData: parameters });
 
         Ajax.api(this, {
           actionName: "save",
index ae1c70d701bd5903323e8f02f77f5d37893b4cfe..f195f438cb39eb597dde49e41632a0d942cec1a1 100644 (file)
@@ -21,6 +21,7 @@ import ControllerCaptcha from "../../Controller/Captcha";
 import * as UiScroll from "../Scroll";
 
 import { CKEditor, getCkeditor } from "../../Component/Ckeditor";
+import { dispatchToCkeditor } from "WoltLabSuite/Core/Component/Ckeditor/Event";
 
 interface MessageReplyOptions {
   ajax: {
@@ -188,7 +189,7 @@ class UiMessageReply {
         });
     }
 
-    EventHandler.fire("com.woltlab.wcf.ckeditor5", "submit_text", parameters.data as any);
+    dispatchToCkeditor(this._textarea).collectMetaData({ metaData: parameters.data as Record<string, unknown> });
 
     if (!User.userId && !additionalParameters) {
       parameters.requireGuestDialog = true;
index 95104dfdfc5aff729e2ba705eccfcc2e4fa4af87..45895d0355f7f5cf2461df87c5a9773d1cdc066a 100644 (file)
@@ -138,6 +138,11 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                                        })
                                        .discardRecoveredData(() => {
                                                discardAllAttachments();
+                                       })
+                                       .collectMetaData((payload) => {
+                                               if (this._tmpHash) {
+                                                       payload.metaData.tmpHash = this._tmpHash;
+                                               }
                                        });
                                
                                const ckeditor = getCkeditor(this._sourceElement);
index f689552a65cb635792d2edfafd2b628aae13a239..46527dbc92f307d3fa83bb7ba0dca4783d42aa16 100644 (file)
@@ -16,6 +16,11 @@ define(["require", "exports"], function (require, exports) {
         constructor(element) {
             this.#element = element;
         }
+        collectMetaData(payload) {
+            this.#element.dispatchEvent(new CustomEvent("ckeditor5:collect-meta-data" /* EventNames.CollectMetaData */, {
+                detail: payload,
+            }));
+        }
         destroy() {
             this.#element.dispatchEvent(new CustomEvent("ckeditor5:destroy" /* EventNames.Destroy */));
         }
@@ -78,6 +83,12 @@ define(["require", "exports"], function (require, exports) {
         constructor(element) {
             this.#element = element;
         }
+        collectMetaData(callback) {
+            this.#element.addEventListener("ckeditor5:collect-meta-data" /* EventNames.CollectMetaData */, (event) => {
+                callback(event.detail);
+            });
+            return this;
+        }
         destroy(callback) {
             this.#element.addEventListener("ckeditor5:destroy" /* EventNames.Destroy */, () => {
                 callback();
index eb2d0c0cbf76c2a834e4885d9e359641b109f54a..9ae1fc64d322fc7af140cf90aea58d07bf6867c7 100644 (file)
@@ -5,7 +5,7 @@
  * @copyright  2001-2021 WoltLab GmbH
  * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
-define(["require", "exports", "tslib", "../../Ajax", "../../Component/Ckeditor", "../../Core", "../../Dom/Change/Listener", "../../Dom/Util", "../../Event/Handler", "../../Language", "../Dropdown/Reusable", "../Notification", "../Screen", "../Scroll"], function (require, exports, tslib_1, Ajax, Ckeditor_1, Core, Listener_1, Util_1, EventHandler, Language, UiDropdownReusable, UiNotification, UiScreen, UiScroll) {
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Event", "../../Ajax", "../../Component/Ckeditor", "../../Core", "../../Dom/Change/Listener", "../../Dom/Util", "../../Event/Handler", "../../Language", "../Dropdown/Reusable", "../Notification", "../Screen", "../Scroll"], function (require, exports, tslib_1, Event_1, Ajax, Ckeditor_1, Core, Listener_1, Util_1, EventHandler, Language, UiDropdownReusable, UiNotification, UiScreen, UiScroll) {
     "use strict";
     Ajax = tslib_1.__importStar(Ajax);
     Core = tslib_1.__importStar(Core);
@@ -380,7 +380,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Component/Ckeditor",
                 }
             }
             validateResult.then(() => {
-                EventHandler.fire("com.woltlab.wcf.ckeditor5", `submit_${id}`, parameters);
+                (0, Event_1.dispatchToCkeditor)(ckeditor.sourceElement).collectMetaData({ metaData: parameters });
                 Ajax.api(this, {
                     actionName: "save",
                     parameters: parameters,
index 8c49fb37d1fbae968301e1a11661a3e190e2b6e3..eb80e1f04696205c6cdd799629bccaa034414a53 100644 (file)
@@ -6,7 +6,7 @@
  * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @woltlabExcludeBundle tiny
  */
-define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Event/Handler", "../../Language", "../../Dom/Change/Listener", "../../Dom/Util", "../Dialog", "../Notification", "../../User", "../../Controller/Captcha", "../Scroll", "../../Component/Ckeditor"], function (require, exports, tslib_1, Ajax, Core, EventHandler, Language, Listener_1, Util_1, Dialog_1, UiNotification, User_1, Captcha_1, UiScroll, Ckeditor_1) {
+define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Event/Handler", "../../Language", "../../Dom/Change/Listener", "../../Dom/Util", "../Dialog", "../Notification", "../../User", "../../Controller/Captcha", "../Scroll", "../../Component/Ckeditor", "WoltLabSuite/Core/Component/Ckeditor/Event"], function (require, exports, tslib_1, Ajax, Core, EventHandler, Language, Listener_1, Util_1, Dialog_1, UiNotification, User_1, Captcha_1, UiScroll, Ckeditor_1, Event_1) {
     "use strict";
     Ajax = tslib_1.__importStar(Ajax);
     Core = tslib_1.__importStar(Core);
@@ -145,7 +145,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Event/
                     parameters[name] = element.value.trim();
                 });
             }
-            EventHandler.fire("com.woltlab.wcf.ckeditor5", "submit_text", parameters.data);
+            (0, Event_1.dispatchToCkeditor)(this._textarea).collectMetaData({ metaData: parameters.data });
             if (!User_1.default.userId && !additionalParameters) {
                 parameters.requireGuestDialog = true;
             }