diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f35b8b6f3..9f624d178 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -41,7 +41,7 @@ use OCA\Talk\Events\RoomEvent; use OCA\Talk\Deck\DeckPluginLoader; use OCA\Talk\Files\Listener as FilesListener; use OCA\Talk\Files\TemplateLoader as FilesTemplateLoader; -use OCA\Talk\Flow\Operation; +use OCA\Talk\Flow\RegisterOperationsListener; use OCA\Talk\Listener\BeforeUserLoggedOutListener; use OCA\Talk\Listener\CSPListener; use OCA\Talk\Listener\FeaturePolicyListener; @@ -84,6 +84,7 @@ use OCP\Settings\IManager; use OCP\User\Events\BeforeUserLoggedOutEvent; use OCP\User\Events\UserChangedEvent; use OCP\User\Events\UserDeletedEvent; +use OCP\WorkflowEngine\Events\RegisterOperationsEvent; class Application extends App implements IBootstrap { public const APP_ID = 'spreed'; @@ -109,6 +110,7 @@ class Application extends App implements IBootstrap { $context->registerEventListener(\OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent::class, UnifiedSearchCSSLoader::class); $context->registerEventListener(UserChangedEvent::class, UserDisplayNameListener::class); $context->registerEventListener(\OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent::class, DeckPluginLoader::class); + $context->registerEventListener(RegisterOperationsEvent::class, RegisterOperationsListener::class); $context->registerSearchProvider(ConversationSearch::class); $context->registerSearchProvider(CurrentMessageSearch::class); @@ -143,7 +145,6 @@ class Application extends App implements IBootstrap { ResourceListener::register($dispatcher); ChangelogListener::register($dispatcher); ShareListener::register($dispatcher); - Operation::register($dispatcher); $this->registerRoomActivityHooks($dispatcher); $this->registerChatHooks($dispatcher); diff --git a/lib/Flow/Operation.php b/lib/Flow/Operation.php index 3110e793e..3e536b493 100644 --- a/lib/Flow/Operation.php +++ b/lib/Flow/Operation.php @@ -32,19 +32,16 @@ use OCA\Talk\Manager as TalkManager; use OCA\Talk\Participant; use OCA\Talk\Room; use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventDispatcher; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; -use OCP\Util; use OCP\WorkflowEngine\EntityContext\IDisplayText; use OCP\WorkflowEngine\EntityContext\IUrl; use OCP\WorkflowEngine\IEntity; use OCP\WorkflowEngine\IManager as FlowManager; use OCP\WorkflowEngine\IOperation; use OCP\WorkflowEngine\IRuleMatcher; -use Symfony\Component\EventDispatcher\GenericEvent; use UnexpectedValueException; class Operation implements IOperation { @@ -81,14 +78,6 @@ class Operation implements IOperation { $this->chatManager = $chatManager; } - public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener(FlowManager::EVENT_NAME_REG_OPERATION, function (GenericEvent $event) { - $operation = \OC::$server->query(Operation::class); - $event->getSubject()->registerOperation($operation); - Util::addScript('spreed', 'flow'); - }); - } - public function getDisplayName(): string { return $this->l->t('Write to conversation'); } diff --git a/lib/Flow/RegisterOperationsListener.php b/lib/Flow/RegisterOperationsListener.php new file mode 100644 index 000000000..aff49855a --- /dev/null +++ b/lib/Flow/RegisterOperationsListener.php @@ -0,0 +1,49 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Talk\Flow; + +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; +use OCP\WorkflowEngine\Events\RegisterOperationsEvent; + +class RegisterOperationsListener implements IEventListener { + + /** @var Operation */ + private $operation; + + public function __construct(Operation $operation) { + $this->operation = $operation; + } + + public function handle(Event $event): void { + if (!($event instanceof RegisterOperationsEvent)) { + // Unrelated + return; + } + + $event->registerOperation($this->operation); + Util::addScript('spreed', 'flow'); + } +}