Register flow operation via dedicated event

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-05-21 07:25:30 +02:00
Родитель 8d61c84e2b
Коммит 7b3e45e926
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
3 изменённых файлов: 52 добавлений и 13 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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');
}

Просмотреть файл

@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
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');
}
}