From f3f0ccd01bb0ed4ebb58196b16afb904627ecb1c Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 23 Oct 2023 07:54:00 +0800 Subject: [PATCH] DEV: Switch to new `addComposerToolbarPopupMenuOption` plugin API (#59) Why this change? `api.addToolbarPopupMenuOptionsCallback` has been deprecated in https://github.com/discourse/discourse/commit/913fd3a7b392b492f6344102577960a6eada00ce --- .discourse-compatibility | 1 + .../composer-toolbar-webinar-button.js | 35 +++++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/.discourse-compatibility b/.discourse-compatibility index 3ef32c3..cf92624 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,2 +1,3 @@ +< 3.2.0.beta2: 6f5f00f7ee610da254b356ad11e9f3665235dcd6 3.1.999: d5ff8a7832ace8355e60a427e2269e81575a4707 2.7.0.beta3: 81120be3a7602834a18e93ddbd1a69bbf7ebb608 diff --git a/assets/javascripts/discourse/initializers/composer-toolbar-webinar-button.js b/assets/javascripts/discourse/initializers/composer-toolbar-webinar-button.js index 2a2b28e..8d9bea1 100644 --- a/assets/javascripts/discourse/initializers/composer-toolbar-webinar-button.js +++ b/assets/javascripts/discourse/initializers/composer-toolbar-webinar-button.js @@ -2,29 +2,20 @@ import { withPluginApi } from "discourse/lib/plugin-api"; import showModal from "discourse/lib/show-modal"; function initializeWebinarButton(api) { - api.modifyClass("controller:composer", { - pluginId: "discourse-zoom", + const composerService = api.container.lookup("service:composer"); - actions: { - showWebinarModal() { - showModal("webinar-picker", { - model: this.model, - title: "zoom.webinar_picker.title", - }); - }, + api.addComposerToolbarPopupMenuOption({ + condition: (composer) => { + return composer.model && composer.model.creatingTopic; + }, + icon: "video", + label: "zoom.webinar_picker.button", + action: () => { + showModal("webinar-picker", { + model: composerService.model, + title: "zoom.webinar_picker.title", + }); }, - }); - - api.addToolbarPopupMenuOptionsCallback((controller) => { - const composer = controller.model; - if (composer && composer.creatingTopic) { - return { - id: "associate_webinar_button", - icon: "video", - action: "showWebinarModal", - label: "zoom.webinar_picker.button", - }; - } }); } @@ -35,7 +26,7 @@ export default { const siteSettings = container.lookup("site-settings:main"); const currentUser = container.lookup("current-user:main"); if (siteSettings.zoom_enabled && currentUser) { - withPluginApi("0.5", initializeWebinarButton); + withPluginApi("1.15.0", initializeWebinarButton); } }, };