diff options
author | Joas Schilling <coding@schilljs.com> | 2019-12-03 13:48:13 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-12-04 08:36:59 +0100 |
commit | 81db771748c2a35c0d953d608c9996a3cdf02102 (patch) | |
tree | 7cb291a5df69ce3d60ac0bc71e577af09c8d8e28 | |
parent | 0e1d2b39b92c77d2c58ef60c525677957713e546 (diff) |
Add constants for event names and use pattern
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Activity/Listener.php | 10 | ||||
-rw-r--r-- | lib/AppInfo/Application.php | 6 | ||||
-rw-r--r-- | lib/Chat/Changelog/Listener.php | 2 | ||||
-rw-r--r-- | lib/Chat/ChatManager.php | 20 | ||||
-rw-r--r-- | lib/Chat/Command/Executor.php | 4 | ||||
-rw-r--r-- | lib/Chat/Command/Listener.php | 2 | ||||
-rw-r--r-- | lib/Chat/MessageParser.php | 4 | ||||
-rw-r--r-- | lib/Chat/Parser/Listener.php | 8 | ||||
-rw-r--r-- | lib/Chat/SystemMessage/Listener.php | 34 | ||||
-rw-r--r-- | lib/Collaboration/Resources/Listener.php | 14 | ||||
-rw-r--r-- | lib/Controller/RoomController.php | 9 | ||||
-rw-r--r-- | lib/Controller/SignalingController.php | 4 | ||||
-rw-r--r-- | lib/Files/Listener.php | 4 | ||||
-rw-r--r-- | lib/GuestManager.php | 10 | ||||
-rw-r--r-- | lib/Listener/RestrictStartingCalls.php | 2 | ||||
-rw-r--r-- | lib/Manager.php | 6 | ||||
-rw-r--r-- | lib/Notification/Listener.php | 8 | ||||
-rw-r--r-- | lib/PublicShareAuth/Listener.php | 12 | ||||
-rw-r--r-- | lib/Room.php | 120 | ||||
-rw-r--r-- | lib/Share/RoomShareProvider.php | 6 | ||||
-rw-r--r-- | lib/Signaling/Listener.php | 62 | ||||
-rw-r--r-- | tests/php/Chat/Command/ExecutorTest.php | 2 | ||||
-rw-r--r-- | tests/php/Controller/SignalingControllerTest.php | 2 | ||||
-rw-r--r-- | tests/php/RoomTest.php | 2 |
24 files changed, 188 insertions, 165 deletions
diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index e2bb53946..d7db36a98 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -69,23 +69,23 @@ class Listener { $listener = \OC::$server->query(self::class); $listener->setActive($event->getRoom()); }; - $dispatcher->addListener(Room::class . '::postSessionJoinCall', $listener); + $dispatcher->addListener(Room::EVENT_AFTER_SESSION_JOIN_CALL, $listener); $listener = static function(RoomEvent $event) { /** @var self $listener */ $listener = \OC::$server->query(self::class); $listener->generateCallActivity($event->getRoom()); }; - $dispatcher->addListener(Room::class . '::postRemoveBySession', $listener); - $dispatcher->addListener(Room::class . '::postRemoveUser', $listener); - $dispatcher->addListener(Room::class . '::postSessionLeaveCall', $listener, -100); + $dispatcher->addListener(Room::EVENT_AFTER_PARTICIPANT_REMOVE, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_USER_REMOVE, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_SESSION_LEAVE_CALL, $listener, -100); $listener = static function(AddParticipantsEvent $event) { /** @var self $listener */ $listener = \OC::$server->query(self::class); $listener->generateInvitationActivity($event->getRoom(), $event->getParticipants()); }; - $dispatcher->addListener(Room::class . '::postAddUsers', $listener); + $dispatcher->addListener(Room::EVENT_AFTER_USERS_ADD, $listener); } public function setActive(Room $room): void { diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 81bae9319..e9daa42a4 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -153,8 +153,8 @@ class Application extends App { $room->setLastActivity($timeFactory->getDateTime()); }; - $dispatcher->addListener(ChatManager::class . '::postSendMessage', $listener); - $dispatcher->addListener(ChatManager::class . '::postSendSystemMessage', $listener); + $dispatcher->addListener(ChatManager::EVENT_AFTER_MESSAGE_SEND, $listener); + $dispatcher->addListener(ChatManager::EVENT_AFTER_SYSTEM_MESSAGE_SEND, $listener); } protected function registerChatHooks(IEventDispatcher $dispatcher): void { @@ -163,6 +163,6 @@ class Application extends App { $chatManager = $this->getContainer()->query(ChatManager::class); $chatManager->deleteMessages($event->getRoom()); }; - $dispatcher->addListener(Room::class . '::postDeleteRoom', $listener); + $dispatcher->addListener(Room::EVENT_AFTER_ROOM_DELETE, $listener); } } diff --git a/lib/Chat/Changelog/Listener.php b/lib/Chat/Changelog/Listener.php index a24d108eb..8ce066b27 100644 --- a/lib/Chat/Changelog/Listener.php +++ b/lib/Chat/Changelog/Listener.php @@ -29,7 +29,7 @@ use OCP\EventDispatcher\IEventDispatcher; class Listener { public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener(RoomController::class . '::preGetRooms', static function(UserEvent $event) { + $dispatcher->addListener(RoomController::EVENT_BEFORE_ROOMS_GET, static function(UserEvent $event) { $userId = $event->getUserId(); /** @var Listener $listener */ diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 83752aea2..75cafecd1 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -46,6 +46,11 @@ use OCP\IUser; */ class ChatManager { + public const EVENT_BEFORE_SYSTEM_MESSAGE_SEND = self::class . '::preSendSystemMessage'; + public const EVENT_AFTER_SYSTEM_MESSAGE_SEND = self::class . '::postSendSystemMessage'; + public const EVENT_BEFORE_MESSAGE_SEND = self::class . '::preSendMessage'; + public const EVENT_AFTER_MESSAGE_SEND = self::class . '::postSendMessage'; + public const MAX_CHAT_LENGTH = 32000; /** @var CommentsManager|ICommentsManager */ @@ -83,6 +88,9 @@ class ChatManager { $comment->setMessage($message, self::MAX_CHAT_LENGTH); $comment->setCreationDateTime($creationDateTime); $comment->setVerb('system'); + + $event = new ChatEvent($chat, $comment); + $this->dispatcher->dispatch(self::EVENT_BEFORE_SYSTEM_MESSAGE_SEND, $event); try { $this->commentsManager->save($comment); @@ -93,8 +101,7 @@ class ChatManager { $this->notifier->notifyOtherParticipant($chat, $comment, []); } - $event = new ChatEvent($chat, $comment); - $this->dispatcher->dispatch(self::class . '::postSendSystemMessage', $event); + $this->dispatcher->dispatch(self::EVENT_AFTER_SYSTEM_MESSAGE_SEND, $event); } catch (NotFoundException $e) { } @@ -115,14 +122,15 @@ class ChatManager { $comment->setCreationDateTime($this->timeFactory->getDateTime()); $comment->setVerb('comment'); // Has to be comment, so it counts as unread message + $event = new ChatEvent($chat, $comment); + $this->dispatcher->dispatch(self::EVENT_BEFORE_SYSTEM_MESSAGE_SEND, $event); try { $this->commentsManager->save($comment); // Update last_message $chat->setLastMessage($comment); - $event = new ChatEvent($chat, $comment); - $this->dispatcher->dispatch(self::class . '::postSendSystemMessage', $event); + $this->dispatcher->dispatch(self::EVENT_AFTER_SYSTEM_MESSAGE_SEND, $event); } catch (NotFoundException $e) { } @@ -154,7 +162,7 @@ class ChatManager { } $event = new ChatParticipantEvent($chat, $comment, $participant); - $this->dispatcher->dispatch(self::class . '::preSendMessage', $event); + $this->dispatcher->dispatch(self::EVENT_BEFORE_MESSAGE_SEND, $event); try { $this->commentsManager->save($comment); @@ -175,7 +183,7 @@ class ChatManager { // User was not mentioned, send a normal notification $this->notifier->notifyOtherParticipant($chat, $comment, $alreadyNotifiedUsers); - $this->dispatcher->dispatch(self::class . '::postSendMessage', $event); + $this->dispatcher->dispatch(self::EVENT_AFTER_MESSAGE_SEND, $event); } catch (NotFoundException $e) { } diff --git a/lib/Chat/Command/Executor.php b/lib/Chat/Command/Executor.php index a6f45bc26..661ecbd0c 100644 --- a/lib/Chat/Command/Executor.php +++ b/lib/Chat/Command/Executor.php @@ -36,6 +36,8 @@ use OCP\ILogger; class Executor { + public const EVENT_APP_EXECUTE = self::class . '::execApp'; + public const PLACEHOLDER_ROOM = '{ROOM}'; public const PLACEHOLDER_USER = '{USER}'; public const PLACEHOLDER_ARGUMENTS = '{ARGUMENTS}'; @@ -172,7 +174,7 @@ class Executor { protected function execApp(Room $room, IComment $message, Command $command, string $arguments): string { $event = $this->createEvent($room, $message, $command, $arguments); - $this->dispatcher->dispatch(self::class . '::execApp', $event); + $this->dispatcher->dispatch(self::EVENT_APP_EXECUTE, $event); return $event->getOutput(); } diff --git a/lib/Chat/Command/Listener.php b/lib/Chat/Command/Listener.php index 5342d3d9f..cb370dbf6 100644 --- a/lib/Chat/Command/Listener.php +++ b/lib/Chat/Command/Listener.php @@ -44,7 +44,7 @@ class Listener { } public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener(ChatManager::class . '::preSendMessage', static function(ChatParticipantEvent $event) { + $dispatcher->addListener(ChatManager::EVENT_BEFORE_MESSAGE_SEND, static function(ChatParticipantEvent $event) { $message = $event->getComment(); $participant = $event->getParticipant(); diff --git a/lib/Chat/MessageParser.php b/lib/Chat/MessageParser.php index eeb3c7de1..ba46c718b 100644 --- a/lib/Chat/MessageParser.php +++ b/lib/Chat/MessageParser.php @@ -41,6 +41,8 @@ use OCP\IUserManager; */ class MessageParser { + public const EVENT_MESSAGE_PARSE = self::class . '::parseMessage'; + /** @var IEventDispatcher */ private $dispatcher; @@ -71,7 +73,7 @@ class MessageParser { $this->setActor($message); $event = new ChatMessageEvent($message); - $this->dispatcher->dispatch(self::class . '::parseMessage', $event); + $this->dispatcher->dispatch(self::EVENT_MESSAGE_PARSE, $event); } protected function setActor(Message $message): void { diff --git a/lib/Chat/Parser/Listener.php b/lib/Chat/Parser/Listener.php index c17b0ff27..fbda032e6 100644 --- a/lib/Chat/Parser/Listener.php +++ b/lib/Chat/Parser/Listener.php @@ -30,7 +30,7 @@ use OCP\EventDispatcher\IEventDispatcher; class Listener { public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) { + $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function(ChatMessageEvent $event) { $message = $event->getMessage(); if ($message->getMessageType() !== 'comment') { @@ -42,7 +42,7 @@ class Listener { $parser->parseMessage($message); }, -100); - $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) { + $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function(ChatMessageEvent $event) { $message = $event->getMessage(); if ($message->getMessageType() !== 'comment') { @@ -59,7 +59,7 @@ class Listener { } }, -75); - $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) { + $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function(ChatMessageEvent $event) { $message = $event->getMessage(); if ($message->getMessageType() !== 'system') { @@ -77,7 +77,7 @@ class Listener { } }); - $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) { + $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function(ChatMessageEvent $event) { $chatMessage = $event->getMessage(); if ($chatMessage->getMessageType() !== 'command') { diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php index e6c652db0..71ea8c625 100644 --- a/lib/Chat/SystemMessage/Listener.php +++ b/lib/Chat/SystemMessage/Listener.php @@ -65,7 +65,7 @@ class Listener { } public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener(Room::class . '::preSessionJoinCall', static function(ModifyParticipantEvent $event) { + $dispatcher->addListener(Room::EVENT_BEFORE_SESSION_JOIN_CALL, static function(ModifyParticipantEvent $event) { $room = $event->getRoom(); /** @var self $listener */ $listener = \OC::$server->query(self::class); @@ -76,7 +76,7 @@ class Listener { $listener->sendSystemMessage($room, 'call_started'); } }); - $dispatcher->addListener(Room::class . '::postSessionLeaveCall', static function(ModifyParticipantEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_SESSION_LEAVE_CALL, static function(ModifyParticipantEvent $event) { $room = $event->getRoom(); /** @var self $listener */ $listener = \OC::$server->query(self::class); @@ -84,14 +84,14 @@ class Listener { $listener->sendSystemMessage($room, 'call_left'); }); - $dispatcher->addListener(Room::class . '::createdRoom', static function(RoomEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_ROOM_CREATE, static function(RoomEvent $event) { $room = $event->getRoom(); /** @var self $listener */ $listener = \OC::$server->query(self::class); $listener->sendSystemMessage($room, 'conversation_created'); }); - $dispatcher->addListener(Room::class . '::postSetName', static function(ModifyRoomEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_NAME_SET, static function(ModifyRoomEvent $event) { if ($event->getOldValue() === '' || $event->getNewValue() === '') { return; @@ -106,7 +106,7 @@ class Listener { 'oldName' => $event->getOldValue(), ]); }); - $dispatcher->addListener(Room::class . '::postSetPassword', static function(ModifyRoomEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_PASSWORD_SET, static function(ModifyRoomEvent $event) { $room = $event->getRoom(); /** @var self $listener */ $listener = \OC::$server->query(self::class); @@ -117,7 +117,7 @@ class Listener { $listener->sendSystemMessage($room, 'password_removed'); } }); - $dispatcher->addListener(Room::class . '::postSetType', static function(ModifyRoomEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_TYPE_SET, static function(ModifyRoomEvent $event) { $room = $event->getRoom(); if ($event->getNewValue() === Room::PUBLIC_CALL) { @@ -130,7 +130,7 @@ class Listener { $listener->sendSystemMessage($room, 'guests_disallowed'); } }); - $dispatcher->addListener(Room::class . '::postSetReadOnly', static function(ModifyRoomEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_READONLY_SET, static function(ModifyRoomEvent $event) { $room = $event->getRoom(); if ($room->getType() === Room::CHANGELOG_CONVERSATION) { @@ -146,7 +146,7 @@ class Listener { $listener->sendSystemMessage($room, 'read_only_off'); } }); - $dispatcher->addListener(Room::class . '::postSetLobbyState', static function(ModifyLobbyEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_LOBBY_STATE_SET, static function(ModifyLobbyEvent $event) { if ($event->getNewValue() === $event->getOldValue()) { return; } @@ -165,7 +165,7 @@ class Listener { } }); - $dispatcher->addListener(Room::class . '::postAddUsers', static function(AddParticipantsEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_USERS_ADD, static function(AddParticipantsEvent $event) { $participants = $event->getParticipants(); $user = \OC::$server->getUserSession()->getUser(); $userId = $user instanceof IUser ? $user->getUID() : null; @@ -186,7 +186,7 @@ class Listener { } } }); - $dispatcher->addListener(Room::class . '::postRemoveUser', static function(RemoveUserEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_USER_REMOVE, static function(RemoveUserEvent $event) { $room = $event->getRoom(); if ($room->getType() === Room::ONE_TO_ONE_CALL) { @@ -197,7 +197,7 @@ class Listener { $listener = \OC::$server->query(self::class); $listener->sendSystemMessage($room, 'user_removed', ['user' => $event->getUser()->getUID()]); }); - $dispatcher->addListener(Room::class . '::postSetParticipantType', static function(ModifyParticipantEvent $event) { + $dispatcher->addListener(Room::EVENT_AFTER_PARTICIPANT_TYPE_SET, static function(ModifyParticipantEvent $event) { $room = $event->getRoom(); if ($event->getNewValue() === Participa |