Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-11-27 18:31:44 +0300
committerJoas Schilling <coding@schilljs.com>2019-12-04 10:36:59 +0300
commit0e1d2b39b92c77d2c58ef60c525677957713e546 (patch)
tree745d723c175ff8ab2967b0e939f55a4d0d1da221
parentff7efea822e95e8927929140995ed5031bec5d80 (diff)
Typed events for Talk
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--docs/events.md147
-rw-r--r--lib/Activity/Listener.php29
-rw-r--r--lib/AppInfo/Application.php37
-rw-r--r--lib/Chat/Changelog/Listener.php10
-rw-r--r--lib/Chat/ChatManager.php32
-rw-r--r--lib/Chat/Command/Executor.php24
-rw-r--r--lib/Chat/Command/Listener.php28
-rw-r--r--lib/Chat/MessageParser.php11
-rw-r--r--lib/Chat/Parser/Listener.php27
-rw-r--r--lib/Chat/SystemMessage/Listener.php147
-rw-r--r--lib/Collaboration/Resources/Listener.php49
-rw-r--r--lib/Controller/CallController.php4
-rw-r--r--lib/Controller/ChatController.php2
-rw-r--r--lib/Controller/GuestController.php2
-rw-r--r--lib/Controller/RoomController.php23
-rw-r--r--lib/Controller/SignalingController.php19
-rw-r--r--lib/Events/AddEmailEvent.php46
-rw-r--r--lib/Events/AddParticipantsEvent.php46
-rw-r--r--lib/Events/ChatEvent.php43
-rw-r--r--lib/Events/ChatMessageEvent.php42
-rw-r--r--lib/Events/ChatParticipantEvent.php44
-rw-r--r--lib/Events/CommandEvent.php61
-rw-r--r--lib/Events/CreateRoomTokenEvent.php62
-rw-r--r--lib/Events/JoinRoomGuestEvent.php67
-rw-r--r--lib/Events/JoinRoomUserEvent.php76
-rw-r--r--lib/Events/ModifyLobbyEvent.php60
-rw-r--r--lib/Events/ModifyParticipantEvent.php70
-rw-r--r--lib/Events/ModifyRoomEvent.php68
-rw-r--r--lib/Events/ParticipantEvent.php44
-rw-r--r--lib/Events/RemoveParticipantEvent.php44
-rw-r--r--lib/Events/RemoveUserEvent.php47
-rw-r--r--lib/Events/RoomEvent.php46
-rw-r--r--lib/Events/SignalingEvent.php55
-rw-r--r--lib/Events/UserEvent.php42
-rw-r--r--lib/Events/VerifyRoomPasswordEvent.php63
-rw-r--r--lib/Files/Listener.php25
-rw-r--r--lib/Files/TemplateLoader.php4
-rw-r--r--lib/GuestManager.php31
-rw-r--r--lib/Listener.php8
-rw-r--r--lib/Listener/RestrictStartingCalls.php22
-rw-r--r--lib/Manager.php22
-rw-r--r--lib/Notification/Listener.php36
-rw-r--r--lib/PublicShare/TemplateLoader.php4
-rw-r--r--lib/PublicShareAuth/Listener.php26
-rw-r--r--lib/PublicShareAuth/TemplateLoader.php4
-rw-r--r--lib/Room.php235
-rw-r--r--lib/Share/RoomShareProvider.php29
-rw-r--r--lib/Signaling/Listener.php156
-rw-r--r--tests/php/Chat/ChatManagerTest.php6
-rw-r--r--tests/php/Chat/Command/ExecutorTest.php22
-rw-r--r--tests/php/Chat/Command/ShellExecutorTest.php28
-rw-r--r--tests/php/Controller/RoomControllerTest.php6
-rw-r--r--tests/php/Controller/SignalingControllerTest.php15
-rw-r--r--tests/php/RoomTest.php (renamed from tests/php/PasswordVerificationTest.php)27
-rw-r--r--tests/php/Signaling/BackendNotifierTest.php13
55 files changed, 1641 insertions, 695 deletions
diff --git a/docs/events.md b/docs/events.md
new file mode 100644
index 000000000..db592799b
--- /dev/null
+++ b/docs/events.md
@@ -0,0 +1,147 @@
+# PHP Events
+
+## Conversation related events
+
+### Created conversation
+
+* Event class: `OCA\Talk\Events\RoomEvent`
+* Event name: `OCA\Talk\Room::createdRoom`
+
+### Create token for conversation
+
+* Event class: `OCA\Talk\Events\CreateRoomTokenEvent`
+* Event name: `OCA\Talk\Manager::generateNewToken`
+
+### Set name
+
+* Event class: `OCA\Talk\Events\ModifyRoomEvent`
+* Pre-event name: `OCA\Talk\Room::preSetName`
+* Post-event name: `OCA\Talk\Room::postSetName`
+
+### Set password
+
+* Event class: `OCA\Talk\Events\ModifyRoomEvent`
+ - No old value is provided
+* Pre-event name: `OCA\Talk\Room::preSetPassword`
+* Post-event name: `OCA\Talk\Room::postSetPassword`
+
+### Set type
+
+* Event class: `OCA\Talk\Events\ModifyRoomEvent`
+* Pre-event name: `OCA\Talk\Room::preSetType`
+* Post-event name: `OCA\Talk\Room::postSetType`
+
+### Set read-only
+
+* Event class: `OCA\Talk\Events\ModifyRoomEvent`
+* Pre-event name: `OCA\Talk\Room::preSetReadOnly`
+* Post-event name: `OCA\Talk\Room::postSetReadOnly`
+
+### Set lobby
+
+* Event class: `OCA\Talk\Events\ModifyLobbyEvent`
+* Pre-event name: `OCA\Talk\Room::preSetLobbyState`
+* Post-event name: `OCA\Talk\Room::postSetLobbyState`
+
+### Clean up guests
+
+* Event class: `OCA\Talk\Events\RoomEvent`
+* Pre-event name: `OCA\Talk\Room::preCleanGuests`
+* Post-event name: `OCA\Talk\Room::postCleanGuests`
+
+### Verify password
+
+* Event class: `OCA\Talk\Events\VerifyRoomPasswordEvent`
+* Event name: `OCA\Talk\Room::verifyPassword`
+
+### Delete conversation
+
+* Event class: `OCA\Talk\Events\RoomEvent`
+* Pre-event name: `OCA\Talk\Room::preDeleteRoom`
+* Post-event name: `OCA\Talk\Room::postDeleteRoom`
+
+## Participant related events
+
+### Add participants
+
+* Event class: `OCA\Talk\Events\AddParticipantsEvent`
+* Pre-event name: `OCA\Talk\Room::preAddUsers`
+* Post-event name: `OCA\Talk\Room::postAddUsers`
+
+### Add email
+
+* Event class: `OCA\Talk\Events\AddEmailEvent`
+* Pre-event name: `OCA\Talk\GuestManager::preInviteByEmail`
+* Post-event name: `OCA\Talk\GuestManager::postInviteByEmail`
+
+### Set participant type for user
+
+* Event class: `OCA\Talk\Events\ModifyParticipantEvent`
+* Pre-event name: `OCA\Talk\Room::preSetParticipantType`
+* Post-event name: `OCA\Talk\Room::postSetParticipantType`
+
+### Set participant type for guests
+
+* Event class: `OCA\Talk\Events\ModifyParticipantEvent`
+* Pre-event name: `OCA\Talk\Room::preSetParticipantTypeBySession`
+* Post-event name: `OCA\Talk\Room::postSetParticipantTypeBySession`
+
+### Join a conversation as user
+
+* Event class: `OCA\Talk\Events\JoinRoomUserEvent`
+* Pre-event name: `OCA\Talk\Room::preJoinRoom`
+* Post-event name: `OCA\Talk\Room::postJoinRoom`
+
+### Join a conversation as guest
+
+* Event class: `OCA\Talk\Events\JoinRoomGuestEvent`
+* Pre-event name: `OCA\Talk\Room::preJoinRoomGuest`
+* Post-event name: `OCA\Talk\Room::postJoinRoomGuest`
+
+### Join a call
+
+* Event class: `OCA\Talk\Events\ModifyParticipantEvent`
+* Pre-event name: `OCA\Talk\Room::preSessionJoinCall`
+* Post-event name: `OCA\Talk\Room::postSessionJoinCall`
+
+### Leave a call
+
+* Event class: `OCA\Talk\Events\ModifyParticipantEvent`
+* Pre-event name: `OCA\Talk\Room::preSessionLeaveCall`
+* Post-event name: `OCA\Talk\Room::postSessionLeaveCall`
+
+### Leave conversation
+
+* Event class: `OCA\Talk\Events\ParticipantEvent`
+* Pre-event name: `OCA\Talk\Room::preUserDisconnectRoom`
+* Post-event name: `OCA\Talk\Room::postUserDisconnectRoom`
+
+### Remove user
+
+* Event class: `OCA\Talk\Events\RemoveUserEvent`
+* Pre-event name: `OCA\Talk\Room::preRemoveUser`
+* Post-event name: `OCA\Talk\Room::postRemoveUser`
+
+### Remove participant by session
+
+* Event class: `OCA\Talk\Events\RemoveParticipantEvent`
+* Pre-event name: `OCA\Talk\Room::preRemoveBySession`
+* Post-event name: `OCA\Talk\Room::postRemoveBySession`
+
+## Chat related events
+
+### System message has been posted
+
+* Event class: `OCA\Talk\Events\ChatEvent`
+* Event name: `OCA\Talk\Chat\ChatManager::postSendSystemMessage`
+
+### Post chat message
+
+* Event class: `OCA\Talk\Events\ChatEvent`
+* Pre-event name: `OCA\Talk\Chat\ChatManager::preSendMessage`
+* Post-event name: `OCA\Talk\Chat\ChatManager::postSendMessage`
+
+### Parse chat message
+
+* Event class: `OCA\Talk\Events\ChatMessageEvent`
+* Event name: `OCA\Talk\Chat\MessageParser::parseMessage`
diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php
index 10af0ecd5..e2bb53946 100644
--- a/lib/Activity/Listener.php
+++ b/lib/Activity/Listener.php
@@ -23,14 +23,16 @@ declare(strict_types=1);
namespace OCA\Talk\Activity;
use OCA\Talk\Chat\ChatManager;
+use OCA\Talk\Events\AddParticipantsEvent;
+use OCA\Talk\Events\ModifyParticipantEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Room;
use OCP\Activity\IManager;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Listener {
@@ -61,36 +63,27 @@ class Listener {
$this->timeFactory = $timeFactory;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
-
+ public static function register(IEventDispatcher $dispatcher): void {
+ $listener = static function(ModifyParticipantEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->setActive($room);
+ $listener->setActive($event->getRoom());
};
$dispatcher->addListener(Room::class . '::postSessionJoinCall', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
-
+ $listener = static function(RoomEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->generateCallActivity($room);
+ $listener->generateCallActivity($event->getRoom());
};
$dispatcher->addListener(Room::class . '::postRemoveBySession', $listener);
$dispatcher->addListener(Room::class . '::postRemoveUser', $listener);
$dispatcher->addListener(Room::class . '::postSessionLeaveCall', $listener, -100);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
-
+ $listener = static function(AddParticipantsEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->generateInvitationActivity($room, $event->getArgument('users'));
+ $listener->generateInvitationActivity($event->getRoom(), $event->getParticipants());
};
$dispatcher->addListener(Room::class . '::postAddUsers', $listener);
}
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 8b9cce0d0..81bae9319 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -32,11 +32,12 @@ use OCA\Talk\Chat\SystemMessage\Listener as SystemMessageListener;
use OCA\Talk\Collaboration\Resources\ConversationProvider;
use OCA\Talk\Collaboration\Resources\Listener as ResourceListener;
use OCA\Talk\Config;
+use OCA\Talk\Events\ChatEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Files\Listener as FilesListener;
use OCA\Talk\Files\TemplateLoader as FilesTemplateLoader;
use OCA\Talk\Listener;
use OCA\Talk\Listener\RestrictStartingCalls as RestrictStartingCallsListener;
-use OCA\Talk\Manager;
use OCA\Talk\Middleware\CanUseTalkMiddleware;
use OCA\Talk\Middleware\InjectionMiddleware;
use OCA\Talk\Notification\Listener as NotificationListener;
@@ -48,9 +49,7 @@ use OCA\Talk\Room;
use OCA\Talk\Settings\Personal;
use OCA\Talk\Share\RoomShareProvider;
use OCA\Talk\Signaling\Listener as SignalingListener;
-use OCA\Talk\TalkSession;
use OCP\AppFramework\App;
-use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Collaboration\Resources\IManager as IResourceManager;
use OCP\EventDispatcher\IEventDispatcher;
@@ -59,8 +58,6 @@ use OCP\IUser;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent;
use OCP\Settings\IManager;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends App {
@@ -81,7 +78,9 @@ class Application extends App {
$this->registerCollaborationResourceProvider($server);
$this->getContainer()->registerCapability(Capabilities::class);
- $dispatcher = $server->getEventDispatcher();
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = $server->query(IEventDispatcher::class);
+
Listener::register($dispatcher);
ActivityListener::register($dispatcher);
NotificationListener::register($dispatcher);
@@ -99,10 +98,8 @@ class Application extends App {
ResourceListener::register($dispatcher);
ChangelogListener::register($dispatcher);
- /** @var IEventDispatcher $newDispatcher */
- $newDispatcher = $server->query(IEventDispatcher::class);
- $newDispatcher->addServiceListener(AddContentSecurityPolicyEvent::class, Listener\CSPListener::class);
- $newDispatcher->addServiceListener(AddFeaturePolicyEvent::class, Listener\FeaturePolicyListener::class);
+ $dispatcher->addServiceListener(AddContentSecurityPolicyEvent::class, Listener\CSPListener::class);
+ $dispatcher->addServiceListener(AddFeaturePolicyEvent::class, Listener\FeaturePolicyListener::class);
$this->registerNavigationLink($server);
$this->registerRoomActivityHooks($dispatcher);
@@ -148,27 +145,23 @@ class Application extends App {
});
}
- protected function registerRoomActivityHooks(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ protected function registerRoomActivityHooks(IEventDispatcher $dispatcher): void {
+ $listener = function(ChatEvent $event) {
+ $room = $event->getRoom();
/** @var ITimeFactory $timeFactory */
$timeFactory = $this->getContainer()->query(ITimeFactory::class);
$room->setLastActivity($timeFactory->getDateTime());
};
- $dispatcher->addListener(ChatManager::class . '::sendMessage', $listener);
- $dispatcher->addListener(ChatManager::class . '::sendSystemMessage', $listener);
+ $dispatcher->addListener(ChatManager::class . '::postSendMessage', $listener);
+ $dispatcher->addListener(ChatManager::class . '::postSendSystemMessage', $listener);
}
- protected function registerChatHooks(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
-
+ protected function registerChatHooks(IEventDispatcher $dispatcher): void {
+ $listener = function(RoomEvent $event) {
/** @var ChatManager $chatManager */
$chatManager = $this->getContainer()->query(ChatManager::class);
- $chatManager->deleteMessages($room);
+ $chatManager->deleteMessages($event->getRoom());
};
$dispatcher->addListener(Room::class . '::postDeleteRoom', $listener);
}
diff --git a/lib/Chat/Changelog/Listener.php b/lib/Chat/Changelog/Listener.php
index 4e578206d..a24d108eb 100644
--- a/lib/Chat/Changelog/Listener.php
+++ b/lib/Chat/Changelog/Listener.php
@@ -23,14 +23,14 @@ declare(strict_types=1);
namespace OCA\Talk\Chat\Changelog;
use OCA\Talk\Controller\RoomController;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCA\Talk\Events\UserEvent;
+use OCP\EventDispatcher\IEventDispatcher;
class Listener {
- public static function register(EventDispatcherInterface $dispatcher): void {
- $dispatcher->addListener(RoomController::class . '::preGetRooms', function(GenericEvent $event) {
- $userId = $event->getArgument('userId');
+ public static function register(IEventDispatcher $dispatcher): void {
+ $dispatcher->addListener(RoomController::class . '::preGetRooms', static function(UserEvent $event) {
+ $userId = $event->getUserId();
/** @var Listener $listener */
$listener = \OC::$server->query(self::class);
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index cec0ef126..83752aea2 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -23,15 +23,16 @@ declare(strict_types=1);
namespace OCA\Talk\Chat;
+use OCA\Talk\Events\ChatEvent;
+use OCA\Talk\Events\ChatParticipantEvent;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Basic polling chat manager.
@@ -49,7 +50,7 @@ class ChatManager {
/** @var CommentsManager|ICommentsManager */
private $commentsManager;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var Notifier */
private $notifier;
@@ -57,7 +58,7 @@ class ChatManager {
protected $timeFactory;
public function __construct(CommentsManager $commentsManager,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
Notifier $notifier,
ITimeFactory $timeFactory) {
$this->commentsManager = $commentsManager;
@@ -92,9 +93,8 @@ class ChatManager {
$this->notifier->notifyOtherParticipant($chat, $comment, []);
}
- $this->dispatcher->dispatch(self::class . '::sendSystemMessage', new GenericEvent($chat, [
- 'comment' => $comment,
- ]));
+ $event = new ChatEvent($chat, $comment);
+ $this->dispatcher->dispatch(self::class . '::postSendSystemMessage', $event);
} catch (NotFoundException $e) {
}
@@ -121,9 +121,8 @@ class ChatManager {
// Update last_message
$chat->setLastMessage($comment);
- $this->dispatcher->dispatch(self::class . '::sendSystemMessage', new GenericEvent($chat, [
- 'comment' => $comment,
- ]));
+ $event = new ChatEvent($chat, $comment);
+ $this->dispatcher->dispatch(self::class . '::postSendSystemMessage', $event);
} catch (NotFoundException $e) {
}
@@ -154,11 +153,8 @@ class ChatManager {
$comment->setParentId($replyTo->getId());
}
- $this->dispatcher->dispatch(self::class . '::preSendMessage', new GenericEvent($chat, [
- 'comment' => $comment,
- 'room' => $chat,
- 'participant' => $participant,
- ]));
+ $event = new ChatParticipantEvent($chat, $comment, $participant);
+ $this->dispatcher->dispatch(self::class . '::preSendMessage', $event);
try {
$this->commentsManager->save($comment);
@@ -179,11 +175,7 @@ class ChatManager {
// User was not mentioned, send a normal notification
$this->notifier->notifyOtherParticipant($chat, $comment, $alreadyNotifiedUsers);
- $this->dispatcher->dispatch(self::class . '::sendMessage', new GenericEvent($chat, [
- 'comment' => $comment,
- 'room' => $chat,
- 'participant' => $participant,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSendMessage', $event);
} catch (NotFoundException $e) {
}
diff --git a/lib/Chat/Command/Executor.php b/lib/Chat/Command/Executor.php
index e07b29fe9..a6f45bc26 100644
--- a/lib/Chat/Command/Executor.php
+++ b/lib/Chat/Command/Executor.php
@@ -24,15 +24,15 @@ namespace OCA\Talk\Chat\Command;
use OCA\Talk\Chat\ChatManager;
+use OCA\Talk\Events\CommandEvent;
use OCA\Talk\Model\Command;
use OCA\Talk\Room;
use OCA\Talk\Service\CommandService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Comments\IComment;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\ILogger;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Executor {
@@ -41,7 +41,7 @@ class Executor {
public const PLACEHOLDER_ARGUMENTS = '{ARGUMENTS}';
public const PLACEHOLDER_ARGUMENTS_DOUBLEQUOTE_ESCAPED = '{ARGUMENTS_DOUBLEQUOTE_ESCAPED}';
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
protected $dispatcher;
/** @var ShellExecutor */
@@ -56,7 +56,7 @@ class Executor {
/** @var IL10N */
protected $l;
- public function __construct(EventDispatcherInterface $dispatcher,
+ public function __construct(IEventDispatcher $dispatcher,
ShellExecutor $shellExecutor,
CommandService $commandService,
ILogger $logger,
@@ -171,21 +171,13 @@ class Executor {
}
protected function execApp(Room $room, IComment $message, Command $command, string $arguments): string {
- $event = $this->createEvent($command);
- $event->setArguments([
- 'room' => $room,
- 'message' => $message,
- 'arguments' => $arguments,
- 'output' => '',
- ]);
-
+ $event = $this->createEvent($room, $message, $command, $arguments);
$this->dispatcher->dispatch(self::class . '::execApp', $event);
-
- return (string) $event->getArgument('output');
+ return $event->getOutput();
}
- protected function createEvent(Command $command): GenericEvent {
- return new GenericEvent($command);
+ protected function createEvent(Room $room, IComment $message, Command $command, string $arguments): CommandEvent {
+ return new CommandEvent($room, $message, $command, $arguments);
}
public function execShell(Room $room, IComment $message, Command $command, string $arguments): string {
diff --git a/lib/Chat/Command/Listener.php b/lib/Chat/Command/Listener.php
index 39501abd7..5342d3d9f 100644
--- a/lib/Chat/Command/Listener.php
+++ b/lib/Chat/Command/Listener.php
@@ -24,41 +24,29 @@ namespace OCA\Talk\Chat\Command;
use OCA\Talk\Chat\ChatManager;
-use OCA\Talk\Chat\MessageParser;
-use OCA\Talk\Chat\Parser\Command as CommandParser;
+use OCA\Talk\Events\ChatParticipantEvent;
use OCA\Talk\Model\Command;
-use OCA\Talk\Model\Message;
-use OCA\Talk\Participant;
use OCA\Talk\Service\CommandService;
use OCP\AppFramework\Db\DoesNotExistException;
-use OCP\Comments\IComment;
-use OCP\IUser;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCP\EventDispatcher\IEventDispatcher;
class Listener {
- /** @var EventDispatcherInterface */
- protected $dispatcher;
/** @var CommandService */
protected $commandService;
/** @var Executor */
protected $executor;
- public function __construct(EventDispatcherInterface $dispatcher,
- CommandService $commandService,
+ public function __construct(CommandService $commandService,
Executor $executor) {
- $this->dispatcher = $dispatcher;
$this->commandService = $commandService;
$this->executor = $executor;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- $dispatcher->addListener(ChatManager::class . '::preSendMessage', function(GenericEvent $event) {
- /** @var IComment $message */
- $message = $event->getArgument('comment');
- /** @var Participant $participant */
- $participant = $event->getArgument('participant');
+ public static function register(IEventDispatcher $dispatcher): void {
+ $dispatcher->addListener(ChatManager::class . '::preSendMessage', static function(ChatParticipantEvent $event) {
+ $message = $event->getComment();
+ $participant = $event->getParticipant();
/** @var self $listener */
$listener = \OC::$server->query(self::class);
@@ -88,7 +76,7 @@ class Listener {
return;
}
- $listener->executor->exec($event->getSubject(), $message, $command, $arguments);
+ $listener->executor->exec($event->getRoom(), $message, $command, $arguments);
});
}
diff --git a/lib/Chat/MessageParser.php b/lib/Chat/MessageParser.php
index 8afcb2b3e..eeb3c7de1 100644
--- a/lib/Chat/MessageParser.php
+++ b/lib/Chat/MessageParser.php
@@ -23,24 +23,25 @@ declare(strict_types=1);
namespace OCA\Talk\Chat;
+use OCA\Talk\Events\ChatEvent;
+use OCA\Talk\Events\ChatMessageEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\GuestManager;
use OCA\Talk\Model\Message;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\Comments\IComment;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Helper class to get a rich message from a plain text message.
*/
class MessageParser {
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var IUserManager */
@@ -52,7 +53,7 @@ class MessageParser {
/** @var array */
protected $guestNames = [];
- public function __construct(EventDispatcherInterface $dispatcher,
+ public function __construct(IEventDispatcher $dispatcher,
IUserManager $userManager,
GuestManager $guestManager) {
$this->dispatcher = $dispatcher;
@@ -69,7 +70,7 @@ class MessageParser {
$message->setMessageType($message->getComment()->getVerb());
$this->setActor($message);
- $event = new GenericEvent($message);
+ $event = new ChatMessageEvent($message);
$this->dispatcher->dispatch(self::class . '::parseMessage', $event);
}
diff --git a/lib/Chat/Parser/Listener.php b/lib/Chat/Parser/Listener.php
index 88b608750..c17b0ff27 100644
--- a/lib/Chat/Parser/Listener.php
+++ b/lib/Chat/Parser/Listener.php
@@ -24,16 +24,14 @@ namespace OCA\Talk\Chat\Parser;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Chat\Parser\Command as CommandParser;
-use OCA\Talk\Model\Message;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCA\Talk\Events\ChatMessageEvent;
+use OCP\EventDispatcher\IEventDispatcher;
class Listener {
- public static function register(EventDispatcherInterface $dispatcher): void {
- $dispatcher->addListener(MessageParser::class . '::parseMessage', function(GenericEvent $event) {
- /** @var Message $message */
- $message = $event->getSubject();
+ public static function register(IEventDispatcher $dispatcher): void {
+ $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) {
+ $message = $event->getMessage();
if ($message->getMessageType() !== 'comment') {
return;
@@ -44,9 +42,8 @@ class Listener {
$parser->parseMessage($message);
}, -100);
- $dispatcher->addListener(MessageParser::class . '::parseMessage', function(GenericEvent $event) {
- /** @var Message $message */
- $message = $event->getSubject();
+ $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) {
+ $message = $event->getMessage();
if ($message->getMessageType() !== 'comment') {
return;
@@ -62,9 +59,8 @@ class Listener {
}
}, -75);
- $dispatcher->addListener(MessageParser::class . '::parseMessage', function(GenericEvent $event) {
- /** @var Message $message */
- $message = $event->getSubject();
+ $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) {
+ $message = $event->getMessage();
if ($message->getMessageType() !== 'system') {
return;
@@ -81,9 +77,8 @@ class Listener {
}
});
- $dispatcher->addListener(MessageParser::class . '::parseMessage', function(GenericEvent $event) {
- /** @var Message $chatMessage */
- $chatMessage = $event->getSubject();
+ $dispatcher->addListener(MessageParser::class . '::parseMessage', static function(ChatMessageEvent $event) {
+ $chatMessage = $event->getMessage();
if ($chatMessage->getMessageType() !== 'command') {
return;
diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php
index ed3826cc5..e6c652db0 100644
--- a/lib/Chat/SystemMessage/Listener.php
+++ b/lib/Chat/SystemMessage/Listener.php
@@ -24,6 +24,12 @@ namespace OCA\Talk\Chat\SystemMessage;
use OCA\Talk\Chat\ChatManager;
+use OCA\Talk\Events\AddParticipantsEvent;
+use OCA\Talk\Events\ModifyLobbyEvent;
+use OCA\Talk\Events\ModifyParticipantEvent;
+use OCA\Talk\Events\ModifyRoomEvent;
+use OCA\Talk\Events\RemoveUserEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
@@ -31,16 +37,14 @@ use OCA\Talk\Share\RoomShareProvider;
use OCA\Talk\TalkSession;
use OCA\Talk\Webinary;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IShare;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class Listener {
- /** @var EventDispatcherInterface */
- protected $dispatcher;
/** @var ChatManager */
protected $chatManager;
/** @var TalkSession */
@@ -50,22 +54,19 @@ class Listener {
/** @var ITimeFactory */
protected $timeFactory;
- public function __construct(EventDispatcherInterface $dispatcher,
- ChatManager $chatManager,
+ public function __construct(ChatManager $chatManager,
TalkSession $talkSession,
IUserSession $userSession,
ITimeFactory $timeFactory) {
- $this->dispatcher = $dispatcher;
$this->chatManager = $chatManager;
$this->talkSession = $talkSession;
$this->userSession = $userSession;
$this->timeFactory = $timeFactory;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- $dispatcher->addListener(Room::class . '::preSessionJoinCall', function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ public static function register(IEventDispatcher $dispatcher): void {
+ $dispatcher->addListener(Room::class . '::preSessionJoinCall', static function(ModifyParticipantEvent $event) {
+ $room = $event->getRoom();
/** @var self $listener */
$listener = \OC::$server->query(self::class);
@@ -75,70 +76,62 @@ class Listener {
$listener->sendSystemMessage($room, 'call_started');
}
});
- $dispatcher->addListener(Room::class . '::postSessionLeaveCall', function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $dispatcher->addListener(Room::class . '::postSessionLeaveCall', static function(ModifyParticipantEvent $event) {
+ $room = $event->getRoom();
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->sendSystemMessage($room, 'call_left');
});
- $dispatcher->addListener(Room::class . '::createRoom', function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $dispatcher->addListener(Room::class . '::createdRoom', 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', function(GenericEvent $event) {
- if ($event->getArgument('oldName') === '' ||
- $event->getArgument('newName') === '') {
+ $dispatcher->addListener(Room::class . '::postSetName', static function(ModifyRoomEvent $event) {
+ if ($event->getOldValue() === '' ||
+ $event->getNewValue() === '') {
return;
}
- /** @var Room $room */
- $room = $event->getSubject();
+ $room = $event->getRoom();
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->sendSystemMessage($room, 'conversation_renamed', $event->getArguments());
+ $listener->sendSystemMessage($room, 'conversation_renamed', [
+ 'newName' => $event->getNewValue(),
+ 'oldName' => $event->getOldValue(),
+ ]);
});
- $dispatcher->addListener(Room::class . '::postSetPassword', function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $dispatcher->addListener(Room::class . '::postSetPassword', static function(ModifyRoomEvent $event) {
+ $room = $event->getRoom();
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- if ($event->getArgument('password')) {
+ if ($event->getNewValue() !== '') {
$listener->sendSystemMessage($room, 'password_set');
} else {
$listener->sendSystemMessage($room, 'password_removed');
}
});
- $dispatcher->addListener(Room::class . '::postChangeType', function(GenericEvent $event) {
- $arguments = $event->getArguments();
+ $dispatcher->addListener(Room::class . '::postSetType', static function(ModifyRoomEvent $event) {
+ $room = $event->getRoom();
- /** @var Room $room */
- $room = $event->getSubject();
-
- if ($arguments['newType'] === Room::PUBLIC_CALL) {
+ if ($event->getNewValue() === Room::PUBLIC_CALL) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->sendSystemMessage($room, 'guests_allowed', $event->getArguments());
- }
- if ($arguments['oldType'] === Room::PUBLIC_CALL) {
+ $listener->sendSystemMessage($room, 'guests_allowed');
+ } else if ($event->getNewValue() === Room::GROUP_CALL) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->sendSystemMessage($room, 'guests_disallowed', $event->getArguments());
+ $listener->sendSystemMessage($room, 'guests_disallowed');
}
});
- $dispatcher->addListener(Room::class . '::postSetReadOnly', function(GenericEvent $event) {
- $arguments = $event->getArguments();
-
- /** @var Room $room */
- $room = $event->getSubject();
+ $dispatcher->addListener(Room::class . '::postSetReadOnly', static function(ModifyRoomEvent $event) {
+ $room = $event->getRoom();
if ($room->getType() === Room::CHANGELOG_CONVERSATION) {
return;
@@ -147,41 +140,37 @@ class Listener {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- if ($arguments['newState'] === Room::READ_ONLY) {
- $listener->sendSystemMessage($room, 'read_only', $event->getArguments());
- } else if ($arguments['newState'] === Room::READ_WRITE) {
- $listener->sendSystemMessage($room, 'read_only_off', $event->getArguments());
+ if ($event->getNewValue() === Room::READ_ONLY) {
+ $listener->sendSystemMessage($room, 'read_only');
+ } else if ($event->getNewValue() === Room::READ_WRITE) {
+ $listener->sendSystemMessage($room, 'read_only_off');
}
});
- $dispatcher->addListener(Room::class . '::postSetLobbyState', function(GenericEvent $event) {
- $arguments = $event->getArguments();
-
- if ($arguments['newState'] === $arguments['oldState']) {
+ $dispatcher->addListener(Room::class . '::postSetLobbyState', static function(ModifyLobbyEvent $event) {
+ if ($event->getNewValue() === $event->getOldValue()) {
return;
}
- /** @var Room $room */
- $room = $event->getSubject();
+ $room = $event->getRoom();
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- if ($arguments['timerReached']) {
- $listener->sendSystemMessage($room, 'lobby_timer_reached', $event->getArguments());
- } else if ($arguments['newState'] === Webinary::LOBBY_NONE) {
- $listener->sendSystemMessage($room, 'lobby_none', $event->getArguments());
- } else if ($arguments['newState'] === Webinary::LOBBY_NON_MODERATORS) {
- $listener->sendSystemMessage($room, 'lobby_non_moderators', $event->getArguments());
+ if ($event->isTimerReached()) {
+ $listener->sendSystemMessage($room, 'lobby_timer_reached');
+ } else if ($event->getNewValue() === Webinary::LOBBY_NONE) {
+ $listener->sendSystemMessage($room, 'lobby_none');
+ } else if ($event->getNewValue() === Webinary::LOBBY_NON_MODERATORS) {
+ $listener->sendSystemMessage($room, 'lobby_non_moderators');
}
});
- $dispatcher->addListener(Room::class . '::postAddUsers', function(GenericEvent $event) {
- $participants = $event->getArgument('users');
+ $dispatcher->addListener(Room::class . '::postAddUsers', static function(AddParticipantsEvent $event) {
+ $participants = $event->getParticipants();
$user = \OC::$server->getUserSession()->getUser();
$userId = $user instanceof IUser ? $user->getUID() : null;
- /** @var Room $room */
- $room = $event->getSubject();
+ $room = $event->getRoom();
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
return;
@@ -191,17 +180,14 @@ class Listener {
$listener = \OC::$server->query(self::class);
foreach ($participants as $participant) {
$userJoinedFileRoom = $room->getObjectType() === 'file' &&
- (!array_key_exists('participantType', $participant) || $participant['participantType'] !== Participant::USER_SELF_JOINED);
+ (!isset($participant['participantType']) || $participant['participantType'] !== Participant::USER_SELF_JOINED);
if ($userJoinedFileRoom || $userId !== $participant['userId']) {
$listener->sendSystemMessage($room, 'user_added', ['user' => $participant['userId']]);
}
}
});
- $dispatcher->addListener(Room::class . '::postRemoveUser', function(GenericEvent $event) {
- /** @var IUser $user */
- $user = $event->getArgument('user');
- /** @var Room $room */
- $room = $event->getSubject();
+ $dispatcher->addListener(Room::class . '::postRemoveUser', static function(RemoveUserEvent $event) {
+ $room = $event->getRoom();
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
return;
@@ -209,33 +195,30 @@ class Listener {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->sendSystemMessage($room, 'user_removed', ['user' => $user->getUID()]);
+ $listener->sendSystemMessage($room, 'user_removed', ['user' => $event->getUser()->getUID()]);
});
- $dispatcher->addListener(Room::class . '::postSetParticipantType', function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $dispatcher->addListener(Room::class . '::postSetParticipantType', static function(ModifyParticipantEvent $event) {
+ $room = $event->getRoom();
- if ($event->getArgument('newType') === Participant::MODERATOR) {
+ if ($event->getNewValue() === Participant::MODERATOR) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->sendSystemMessage($room, 'moderator_promoted', ['user' => $event->getArgument('user')]);
- } else if ($event->getArgument('newType') === Participant::USER) {
+ $listener->sendSystemMessage($room, 'moderator_promoted', ['user' => $event->getParticipant()->getUser()]);
+ } else if ($event->getNewValue() === Participant::USER) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->sendSystemMessage($room, 'moderator_demoted', ['user' => $event->getArgument('user')]);
+ $listener->sendSystemMessage($room, 'moderator_demoted', ['user' => $event->getParticipant()->getUser()]);
}
});
- $dispatcher->addListener(Room::class . '::postSetParticipantTypeBySession', function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
- /** @var Participant $participant */
- $participant = $event->getArgument('participant');
+ $dispatcher->addListener(Room::class . '::postSetParticipantTypeBySession', static function(ModifyParticipantEvent $event) {
+ $room = $event->getRoom();
+ $participant = $event->getParticipant();
- if ($event->getArgument('newType') === Participant::GUEST_MODERATOR) {
+ if ($event->getNewValue() === Participant::GUEST_MODERATOR) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->sendSystemMessage($room, 'guest_moderator_promoted', ['session' => sha1($participant->getSessionId())]);
- } else if ($event->getArgument('newType') === Participant::GUEST) {
+ } else if ($event->getNewValue() === Participant::GUEST) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->sendSystemMessage($room, 'guest_moderator_demoted', ['session' => sha1($participant->getSessionId())]);
diff --git a/lib/Collaboration/Resources/Listener.php b/lib/Collaboration/Resources/Listener.php
index c35bd8849..74493aead 100644
--- a/lib/Collaboration/Resources/Listener.php
+++ b/lib/Collaboration/Resources/Listener.php
@@ -22,20 +22,20 @@ declare(strict_types=1);
namespace OCA\Talk\Collaboration\Resources;
-use OCA\Talk\Participant;
+use OCA\Talk\Events\AddParticipantsEvent;
+use OCA\Talk\Events\RemoveParticipantEvent;
+use OCA\Talk\Events\RemoveUserEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Room;
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\ResourceException;
-use OCP\IUser;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserManager;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Listener {
- public static function register(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ public static function register(IEventDispatcher $dispatcher): void {
+ $listener = static function(RoomEvent $event) {
+ $room = $event->getRoom();
/** @var IManager $manager */
$resourceManager = \OC::$server->query(IManager::class);
@@ -48,9 +48,8 @@ class Listener {
};
$dispatcher->addListener(Room::class . '::postDeleteRoom', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $listener = static function(AddParticipantsEvent $event) {
+ $room = $event->getRoom();
/** @var IManager $manager */
$resourceManager = \OC::$server->query(IManager::class);
/** @var IUserManager $userManager */
@@ -61,7 +60,7 @@ class Listener {
return;
}
- $participants = $event->getArgument('users');
+ $participants = $event->getParticipants();
foreach ($participants as $participant) {
$user = null;
if ($participant['user_id'] !== '') {
@@ -71,28 +70,24 @@ class Listener {
$resourceManager->invalidateAccessCacheForResourceByUser($resource, $user);
}
};
- $dispatcher->addListener(Room::class . '::postAddUser', $listener);
+ $dispatcher->addListener(Room::class . '::postAddUsers', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $listener = static function(RemoveUserEvent $event) {
+ $room = $event->getRoom();
/** @var IManager $manager */
$resourceManager = \OC::$server->query(IManager::class);
- /** @var IUser $user */
- $user = $event->getArgument('user');
try {
$resource = $resourceManager->getResourceForUser('room', $room->getToken(), null);
} catch (ResourceException $e) {
return;
}
- $resourceManager->invalidateAccessCacheForResourceByUser($resource, $user);
+ $resourceManager->invalidateAccessCacheForResourceByUser($resource, $event->getUser());
};
$dispatcher->addListener(Room::class . '::postRemoveUser', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $listener = static function(RemoveParticipantEvent $event) {
+ $room = $event->getRoom();
/** @var IManager $manager */
$resourceManager = \OC::$server->query(IManager::class);
/** @var IUserManager $userManager */
@@ -103,16 +98,14 @@ class Listener {
return;
}
- /** @var Participant $participant */
- $participant = $event->getArgument('participant');
+ $participant = $event->getParticipant();
$user = $userManager->get($participant->getUser());
$resourceManager->invalidateAccessCacheForResourceByUser($resource, $user);
};
$dispatcher->addListener(Room::class . '::postRemoveBySession', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $listener = static function(RoomEvent $event) {
+ $room = $event->getRoom();
/** @var IManager $manager */
$resourceManager = \OC::$server->query(IManager::class);
@@ -123,7 +116,7 @@ class Listener {
}
$resourceManager->invalidateAccessCacheForResourceByUser($resource, null);
};
- $dispatcher->addListener(Room::class . '::postChangeType', $listener);
+ $dispatcher->addListener(Room::class . '::postSetType', $listener);
$dispatcher->addListener(Room::class . '::postInviteByEmail', $listener);
}
}
diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php
index 2d9a1ec32..dd8a34514 100644
--- a/lib/Controller/CallController.php
+++ b/lib/Controller/CallController.php
@@ -94,7 +94,7 @@ class CallController extends AEnvironmentAwareController {
$flags = Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO;
}
- $this->room->changeInCall($sessionId, $flags);
+ $this->room->changeInCall($this->participant, $flags);
return new DataResponse();
}
@@ -112,7 +112,7 @@ class CallController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
- $this->room->changeInCall($sessionId, Participant::FLAG_DISCONNECTED);
+ $this->room->changeInCall($this->participant, Participant::FLAG_DISCONNECTED);
return new DataResponse();
}
diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php
index 7e05cc2e5..ed3881b93 100644
--- a/lib/Controller/ChatController.php
+++ b/lib/Controller/ChatController.php
@@ -139,7 +139,7 @@ class ChatController extends AEnvironmentAwareController {
$actorId = $sessionId ? sha1($sessionId) : 'failed-to-get-session';
if ($sessionId && $actorDisplayName) {
- $this->guestManager->updateName($this->room, $sessionId, $actorDisplayName);
+ $this->guestManager->updateName($this->room, $this->participant, $actorDisplayName);
}
} else {
$actorType = 'users';
diff --git a/lib/Controller/GuestController.php b/lib/Controller/GuestController.php
index c3e43cf38..d98e4a7ef 100644
--- a/lib/Controller/GuestController.php
+++ b/lib/Controller/GuestController.php
@@ -61,7 +61,7 @@ class GuestController extends AEnvironmentAwareController {
}
try {
- $this->guestManager->updateName($this->getRoom(), $participant->getSessionId(), $displayName);
+ $this->guestManager->updateName($this->getRoom(), $participant, $displayName);
} catch (DBALException $e) {
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 2e7cb35b8..5201cd3c7 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -28,6 +28,7 @@ namespace OCA\Talk\Controller;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
+use OCA\Talk\Events\UserEvent;
use OCA\Talk\Exceptions\InvalidPasswordException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
@@ -42,14 +43,13 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IGroup;
use OCP\IGroupManager;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class RoomController extends AEnvironmentAwareController {
/** @var string|null */
@@ -66,7 +66,7 @@ class RoomController extends AEnvironmentAwareController {
private $guestManager;
/** @var ChatManager */
private $chatManager;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var MessageParser */
private $messageParser;
@@ -84,7 +84,7 @@ class RoomController extends AEnvironmentAwareController {
Manager $manager,
GuestManager $guestManager,
ChatManager $chatManager,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
MessageParser $messageParser,
ITimeFactory $timeFactory,
IL10N $l10n) {
@@ -110,9 +110,8 @@ class RoomController extends AEnvironmentAwareController {
* @return DataResponse
*/
public function getRooms(): DataResponse {
- $this->dispatcher->dispatch(self::class . '::preGetRooms', new GenericEvent(null, [
- 'userId' => $this->userId,
- ]));
+ $event = new UserEvent($this->userId);
+ $this->dispatcher->dispatch(self::class . '::preGetRooms', $event);
$rooms = $this->manager->getRoomsForParticipant($this->userId, true);
@@ -670,7 +669,7 @@ class RoomController extends AEnvironmentAwareController {
\call_user_func_array([$this->room, 'addUsers'], $participantsToAdd);
} else if ($source === 'emails') {
$data = [];
- if ($this->room->changeType(Room::PUBLIC_CALL)) {
+ if ($this->room->setType(Room::PUBLIC_CALL)) {
$data = ['type' => $this->room->getType()];
}
@@ -790,7 +789,7 @@ class RoomController extends AEnvironmentAwareController {
* @return DataResponse
*/
public function makePublic(): DataResponse {
- if (!$this->room->changeType(Room::PUBLIC_CALL)) {
+ if (!$this->room->setType(Room::PUBLIC_CALL)) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
@@ -804,7 +803,7 @@ class RoomController extends AEnvironmentAwareController {
* @return DataResponse
*/
public function makePrivate(): DataResponse {
- if (!$this->room->changeType(Room::GROUP_CALL)) {
+ if (!$this->room->setType(Room::GROUP_CALL)) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
@@ -934,7 +933,7 @@ class RoomController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
- $room->setParticipantType($participant, Participant::MODERATOR);
+ $room->setParticipantType($targetParticipant, Participant::MODERATOR);
return new DataResponse();
}
@@ -986,7 +985,7 @@ class RoomController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
- $room->setParticipantType($participant, Participant::USER);
+ $room->setParticipantType($targetParticipant, Participant::USER);
return new DataResponse();
}
diff --git a/lib/Controller/SignalingController.php b/lib/Controller/SignalingController.php
index f7b7f26e1..ec25ea3e1 100644
--- a/lib/Controller/SignalingController.php
+++ b/lib/Controller/SignalingController.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use OCA\Talk\Config;
+use OCA\Talk\Events\SignalingEvent;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Manager;
@@ -36,12 +37,11 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class SignalingController extends OCSController {
@@ -60,7 +60,7 @@ class SignalingController extends OCSController {
private $messages;
/** @var IUserManager */
private $userManager;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var ITimeFactory */
private $timeFactory;
@@ -75,7 +75,7 @@ class SignalingController extends OCSController {
IDBConnection $connection,
Messages $messages,
IUserManager $userManager,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
ITimeFactory $timeFactory,
?string $UserId) {
parent::__construct($appName, $request);
@@ -426,12 +426,7 @@ class SignalingController extends OCSController {
}
}
- $event = new GenericEvent($room, [
- 'action' => $action,
- 'participant' => $participant,
- 'sessionid' => $sessionId,
- 'userid' => $userId,
- ]);
+ $event = new SignalingEvent($room, $participant, $action);
$this->dispatcher->dispatch(self::class . '::signalingBackendRoom', $event);
$response = [
@@ -445,8 +440,8 @@ class SignalingController extends OCSController {
],
],
];
- if ($event->hasArgument('roomSession')) {
- $response['room']['session'] = $event->getArgument('roomSession');
+ if ($event->getSession()) {
+ $response['room']['session'] = $event->getSession();
}
return new DataResponse($response);
}
diff --git a/lib/Events/AddEmailEvent.php b/lib/Events/AddEmailEvent.php
new file mode 100644
index 000000000..2e9f5d94b
--- /dev/null
+++ b/lib/Events/AddEmailEvent.php
@@ -0,0 +1,46 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+
+class AddEmailEvent extends RoomEvent {
+
+ /** @var string */
+ protected $email;
+
+
+ public function __construct(Room $room,
+ string $email) {
+ parent::__construct($room);
+ $this->email = $email;
+ }
+
+ /**
+ * @return string
+ */
+ public function getEmail(): string {
+ return $this->email;
+ }
+}
diff --git a/lib/Events/AddParticipantsEvent.php b/lib/Events/AddParticipantsEvent.php
new file mode 100644
index 000000000..7c5b3cdcd
--- /dev/null
+++ b/lib/Events/AddParticipantsEvent.php
@@ -0,0 +1,46 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+
+class AddParticipantsEvent extends RoomEvent {
+
+ /** @var array */
+ protected $participants;
+
+
+ public function __construct(Room $room,
+ array $participants) {
+ parent::__construct($room);
+ $this->participants = $participants;
+ }
+
+ /**
+ * @return array[]
+ */
+ public function getParticipants(): array {
+ return $this->participants;
+ }
+}
diff --git a/lib/Events/ChatEvent.php b/lib/Events/ChatEvent.php
new file mode 100644
index 000000000..44fc6615e
--- /dev/null
+++ b/lib/Events/ChatEvent.php
@@ -0,0 +1,43 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+use OCP\Comments\IComment;
+
+class ChatEvent extends RoomEvent {
+
+ /** @var IComment */
+ protected $comment;
+
+
+ public function __construct(Room $room, IComment $comment) {
+ parent::__construct($room);
+ $this->comment = $comment;
+ }
+
+ public function getComment(): IComment {
+ return $this->comment;
+ }
+}
diff --git a/lib/Events/ChatMessageEvent.php b/lib/Events/ChatMessageEvent.php
new file mode 100644
index 000000000..24fa9c518
--- /dev/null
+++ b/lib/Events/ChatMessageEvent.php
@@ -0,0 +1,42 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Model\Message;
+
+class ChatMessageEvent extends ChatEvent {
+
+ /** @var Message */
+ protected $message;
+
+
+ public function __construct(Message $message) {
+ parent::__construct($message->getRoom(), $message->getComment());
+ $this->message = $message;
+ }
+
+ public function getMessage(): Message {
+ return $this->message;
+ }
+}
diff --git a/lib/Events/ChatParticipantEvent.php b/lib/Events/ChatParticipantEvent.php
new file mode 100644
index 000000000..dded42027
--- /dev/null
+++ b/lib/Events/ChatParticipantEvent.php
@@ -0,0 +1,44 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Participant;
+use OCA\Talk\Room;
+use OCP\Comments\IComment;
+
+class ChatParticipantEvent extends ChatEvent {
+
+ /** @var Participant */
+ protected $participant;
+
+
+ public function __construct(Room $room, IComment $message, Participant $participant) {
+ parent::__construct($room, $message);
+ $this->participant = $participant;
+ }
+
+ public function getParticipant(): Participant {
+ return $this->participant;
+ }
+}
diff --git a/lib/Events/CommandEvent.php b/lib/Events/CommandEvent.php
new file mode 100644
index 000000000..738362d47
--- /dev/null
+++ b/lib/Events/CommandEvent.php
@@ -0,0 +1,61 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Model\Command;
+use OCA\Talk\Room;
+use OCP\Comments\IComment;
+
+class CommandEvent extends ChatEvent {
+
+ /** @var Command */
+ protected $command;
+ /** @var string */
+ protected $arguments;
+ /** @var string */
+ protected $output;
+
+
+ public function __construct(Room $room, IComment $message, Command $command, string $arguments) {
+ parent::__construct($room, $message);
+ $this->command = $command;
+ $this->arguments = $arguments;
+ }
+
+ public function getCommand(): Command {
+ return $this->command;
+ }
+
+ public function getArguments(): string {
+ return $this->arguments;
+ }
+
+ public function setOutput(string $output): void {
+ $this->output = $output;
+ }
+
+ public function getOutput(): string {
+ return $this->output;
+ }
+}
diff --git a/lib/Events/CreateRoomTokenEvent.php b/lib/Events/CreateRoomTokenEvent.php
new file mode 100644
index 000000000..16ec78fba
--- /dev/null
+++ b/lib/Events/CreateRoomTokenEvent.php
@@ -0,0 +1,62 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+use OCP\EventDispatcher\Event;
+
+class CreateRoomTokenEvent extends Event {
+
+ /** @var int */
+ protected $entropy;
+ /** @var string */
+ protected $chars;
+ /** @var string */
+ protected $token;
+
+
+ public function __construct(int $entropy,
+ string $chars) {
+ parent::__construct();
+ $this->entropy = $entropy;
+ $this->chars = $chars;
+ $this->token = '';
+ }
+
+ public function getEntropy(): int {
+ return $this->entropy;
+ }
+
+ public function getChars(): string {
+ return $this->chars;
+ }
+
+ public function setToken(string $token): void {
+ $this->token = $token;
+ }
+
+ public function getToken(): string {
+ return $this->token;
+ }
+}
diff --git a/lib/Events/JoinRoomGuestEvent.php b/lib/Events/JoinRoomGuestEvent.php
new file mode 100644
index 000000000..12fe728ff
--- /dev/null
+++ b/lib/Events/JoinRoomGuestEvent.php
@@ -0,0 +1,67 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+
+class JoinRoomGuestEvent extends RoomEvent {
+
+ /** @var bool */
+ protected $cancelJoin;
+ /** @var string */
+ protected $password;
+ /** @var bool */
+ protected $passedPasswordProtection;
+
+
+ public function __construct(Room $room,
+ string $password,
+ bool $passedPasswordProtection) {
+ parent::__construct($room);
+ $this->cancelJoin = false;
+ $this->password = $password;
+ $this->passedPasswordProtection = $passedPasswordProtection;
+ }
+
+ public function setCancelJoin(bool $cancelJoin): void {
+ $this->cancelJoin = $cancelJoin;
+ }
+
+ public function getCancelJoin(): bool {
+ return $this->cancelJoin;
+ }
+
+ public function getPassword(): string {
+ return $this->password;
+ }
+
+ public function setPassedPasswordProtection(bool $passedPasswordProtection): void {
+ $this->passedPasswordProtection = $passedPasswordProtection;
+ }
+
+ public function getPassedPasswordProtection(): bool {
+ return $this->passedPasswordProtection;
+ }
+
+}
diff --git a/lib/Events/JoinRoomUserEvent.php b/lib/Events/JoinRoomUserEvent.php
new file mode 100644
index 000000000..ea50d3f91
--- /dev/null
+++ b/lib/Events/JoinRoomUserEvent.php
@@ -0,0 +1,76 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+use OCP\IUser;
+
+class JoinRoomUserEvent extends RoomEvent {
+
+ /** @var IUser */
+ protected $user;
+ /** @var bool */
+ protected $cancelJoin;
+ /** @var string */
+ protected $password;
+ /** @var bool */
+ protected $passedPasswordProtection;
+
+
+ public function __construct(Room $room,
+ IUser $user,
+ string $password,
+ bool $passedPasswordProtection) {
+ parent::__construct($room);
+ $this->cancelJoin = false;
+ $this->user = $user;
+ $this->password = $password;
+ $this->passedPasswordProtection = $passedPasswordProtection;
+ }
+
+ public function setCancelJoin(bool $cancelJoin): void {
+ $this->cancelJoin = $cancelJoin;
+ }
+
+ public function getCancelJoin(): bool {
+ return $this->cancelJoin;
+ }
+
+ public function getUser(): IUser {
+ return $this->user;
+ }
+
+ public function getPassword(): string {
+ return $this->password;
+ }
+
+ public function setPassedPasswordProtection(bool $passedPasswordProtection): void {
+ $this->passedPasswordProtection = $passedPasswordProtection;
+ }
+
+ public function getPassedPasswordProtection(): bool {
+ return $this->passedPasswordProtection;
+ }
+
+}
diff --git a/lib/Events/ModifyLobbyEvent.php b/lib/Events/ModifyLobbyEvent.php
new file mode 100644
index 000000000..810109c3e
--- /dev/null
+++ b/lib/Events/ModifyLobbyEvent.php
@@ -0,0 +1,60 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+use OCP\EventDispatcher\Event;
+
+class ModifyLobbyEvent extends ModifyRoomEvent {
+
+ /** @var \DateTime|null */
+ protected $lobbyTimer;
+ /** @var bool */
+ protected $timerReached;
+
+ public function __construct(Room $room,
+ string $parameter,
+ int $newValue,
+ int $oldValue,
+ ?\DateTime $lobbyTimer,
+ bool $timerReached) {
+ parent::__construct($room, $parameter, $newValue, $oldValue);
+ $this->lobbyTimer = $lobbyTimer;
+ $this->timerReached = $timerReached;
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getLobbyTimer(): ?\DateTime {
+ return $this->lobbyTimer;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isTimerReached(): bool {
+ return $this->timerReached;
+ }
+}
diff --git a/lib/Events/ModifyParticipantEvent.php b/lib/Events/ModifyParticipantEvent.php
new file mode 100644
index 000000000..73717866b
--- /dev/null
+++ b/lib/Events/ModifyParticipantEvent.php
@@ -0,0 +1,70 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Participant;
+use OCA\Talk\Room;
+
+class ModifyParticipantEvent extends ParticipantEvent {
+
+ /** @var string */
+ protected $parameter;
+ /** @var int|string|bool */
+ protected $newValue;
+ /** @var int|string|bool|null */
+ protected $oldValue;
+
+
+ public function __construct(Room $room,
+ Participant $participant,
+ string $parameter,
+ $newValue,
+ $oldValue = null) {
+ parent::__construct($room, $participant);
+ $this->parameter = $parameter;
+ $this->newValue = $newValue;
+ $this->oldValue = $oldValue;
+ }
+
+ /**
+ * @return string
+ */
+ public function getParameter(): string {
+ return $this->parameter;
+ }
+
+ /**
+ * @return int|string|bool
+ */
+ public function getNewValue() {
+ return $this->newValue;
+ }
+
+ /**
+ * @return int|string|bool|null
+ */
+ public function getOldValue() {
+ return $this->oldValue;
+ }
+}
diff --git a/lib/Events/ModifyRoomEvent.php b/lib/Events/ModifyRoomEvent.php
new file mode 100644
index 000000000..b3de5c41b
--- /dev/null
+++ b/lib/Events/ModifyRoomEvent.php
@@ -0,0 +1,68 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+
+class ModifyRoomEvent extends RoomEvent {
+
+ /** @var string */
+ protected $parameter;
+ /** @var int|string|bool */
+ protected $newValue;
+ /** @var int|string|bool|null */
+ protected $oldValue;
+
+
+ public function __construct(Room $room,
+ string $parameter,
+ $newValue,
+ $oldValue = null) {
+ parent::__construct($room);
+ $this->parameter = $parameter;
+ $this->newValue = $newValue;
+ $this->oldValue = $oldValue;
+ }
+
+ /**
+ * @return string
+ */
+ public function getParameter(): string {
+ return $this->parameter;
+ }
+
+ /**
+ * @return int|string|bool
+ */
+ public function getNewValue() {
+ return $this->newValue;
+ }
+
+ /**
+ * @return int|string|bool|null
+ */
+ public function getOldValue() {
+ return $this->oldValue;
+ }
+}
diff --git a/lib/Events/ParticipantEvent.php b/lib/Events/ParticipantEvent.php
new file mode 100644
index 000000000..897199a88
--- /dev/null
+++ b/lib/Events/ParticipantEvent.php
@@ -0,0 +1,44 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Participant;
+use OCA\Talk\Room;
+
+class ParticipantEvent extends RoomEvent {
+
+ /** @var Participant */
+ protected $participant;
+
+
+ public function __construct(Room $room,
+ Participant $participant) {
+ parent::__construct($room);
+ $this->participant = $participant;
+ }
+
+ public function getParticipant(): Participant {
+ return $this->participant;
+ }
+}
diff --git a/lib/Events/RemoveParticipantEvent.php b/lib/Events/RemoveParticipantEvent.php
new file mode 100644
index 000000000..ae0b1583e
--- /dev/null
+++ b/lib/Events/RemoveParticipantEvent.php
@@ -0,0 +1,44 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Participant;
+use OCA\Talk\Room;
+
+class RemoveParticipantEvent extends ParticipantEvent {
+
+ /** @var string */
+ protected $reason;
+
+ public function __construct(Room $room,
+ Participant $participant,
+ string $reason) {
+ parent::__construct($room, $participant);
+ $this->reason = $reason;
+ }
+
+ public function getReason(): string {
+ return $this->reason;
+ }
+}
diff --git a/lib/Events/RemoveUserEvent.php b/lib/Events/RemoveUserEvent.php
new file mode 100644
index 000000000..e1af64133
--- /dev/null
+++ b/lib/Events/RemoveUserEvent.php
@@ -0,0 +1,47 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Participant;
+use OCA\Talk\Room;
+use OCP\IUser;
+
+class RemoveUserEvent extends RemoveParticipantEvent {
+
+ /** @var IUser */
+ protected $user;
+
+
+ public function __construct(Room $room,
+ Participant $participant,
+ IUser $user,
+ string $reason) {
+ parent::__construct($room, $participant, $reason);
+ $this->user = $user;
+ }
+
+ public function getUser(): IUser {
+ return $this->user;
+ }
+}
diff --git a/lib/Events/RoomEvent.php b/lib/Events/RoomEvent.php
new file mode 100644
index 000000000..961325bbf
--- /dev/null
+++ b/lib/Events/RoomEvent.php
@@ -0,0 +1,46 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+use OCP\EventDispatcher\Event;
+
+class RoomEvent extends Event {
+
+ /** @var Room */
+ protected $room;
+
+
+ public function __construct(Room $room) {
+ parent::__construct();
+ $this->room = $room;
+ }
+
+ /**
+ * @return Room
+ */
+ public function getRoom(): Room {
+ return $this->room;
+ }
+}
diff --git a/lib/Events/SignalingEvent.php b/lib/Events/SignalingEvent.php
new file mode 100644
index 000000000..615169ae1
--- /dev/null
+++ b/lib/Events/SignalingEvent.php
@@ -0,0 +1,55 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Participant;
+use OCA\Talk\Room;
+
+class SignalingEvent extends ParticipantEvent {
+
+ /** @var string */
+ protected $action;
+ /** @var mixed */
+ protected $session;
+
+ public function __construct(Room $room,
+ Participant $participant,
+ string $action) {
+ parent::__construct($room, $participant);
+ $this->action = $action;
+ $this->session = '';
+ }
+
+ public function getAction(): string {
+ return $this->action;
+ }
+
+ public function setSession($session): void {
+ $this->session = $session;
+ }
+
+ public function getSession() {
+ return $this->session;
+ }
+}
diff --git a/lib/Events/UserEvent.php b/lib/Events/UserEvent.php
new file mode 100644
index 000000000..3ebcedd05
--- /dev/null
+++ b/lib/Events/UserEvent.php
@@ -0,0 +1,42 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCP\EventDispatcher\Event;
+
+class UserEvent extends Event {
+
+ /** @var string */
+ protected $userId;
+
+
+ public function __construct(string $userId) {
+ parent::__construct();
+ $this->userId = $userId;
+ }
+
+ public function getUserId(): string {
+ return $this->userId;
+ }
+}
diff --git a/lib/Events/VerifyRoomPasswordEvent.php b/lib/Events/VerifyRoomPasswordEvent.php
new file mode 100644
index 000000000..d7d2b6d13
--- /dev/null
+++ b/lib/Events/VerifyRoomPasswordEvent.php
@@ -0,0 +1,63 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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\Events;
+
+
+use OCA\Talk\Room;
+
+class VerifyRoomPasswordEvent extends RoomEvent {
+
+ /** @var string */
+ protected $password;
+ /** @var bool|null */
+ protected $isPasswordValid;
+ /** @var string */
+ protected $redirectUrl = '';
+
+
+ public function __construct(Room $room,
+ string $password) {
+ parent::__construct($room);
+ $this->password = $password;
+ }
+
+ public function getPassword(): string {
+ return $this->password;
+ }
+
+ public function setIsPasswordValid(bool $isPasswordValid): void {
+ $this->isPasswordValid = $isPasswordValid;
+ }
+
+ public function isPasswordValid(): ?bool {
+ return $this->isPasswordValid;
+ }
+
+ public function setRedirectUrl(string $redirectUrl): void {
+ $this->redirectUrl = $redirectUrl;
+ }
+
+ public function getRedirectUrl(): string {
+ return $this->redirectUrl;
+ }
+}
diff --git a/lib/Files/Listener.php b/lib/Files/Listener.php
index a71e080cc..7b71ef820 100644
--- a/lib/Files/Listener.php
+++ b/lib/Files/Listener.php
@@ -23,12 +23,13 @@ declare(strict_types=1);
namespace OCA\Talk\Files;
+use OCA\Talk\Events\JoinRoomGuestEvent;
+use OCA\Talk\Events\JoinRoomUserEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Room;
use OCA\Talk\TalkSession;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCP\EventDispatcher\IEventDispatcher;
/**
* Custom behaviour for rooms for files.
@@ -59,32 +60,28 @@ class Listener {
$this->talkSession = $talkSession;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ public static function register(IEventDispatcher $dispatcher): void {
+ $listener = static function(JoinRoomUserEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
try {
- $listener->preventUsersWithoutAccessToTheFileFromJoining($room, $event->getArgument('userId'));
- $listener->addUserAsPersistentParticipant($room, $event->getArgument('userId'));
+ $listener->preventUsersWithoutAccessToTheFileFromJoining($event->getRoom(), $event->getUser()->getUID());
+ $listener->addUserAsPersistentParticipant($event->getRoom(), $event->getUser()->getUID());
} catch (UnauthorizedException $e) {
- $event->setArgument('cancel', true);
+ $event->setCancelJoin(true);
}
};
$dispatcher->addListener(Room::class . '::preJoinRoom', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $listener = static function(JoinRoomGuestEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
try {
- $listener->preventGuestsFromJoiningIfNotPubliclyAccessible($room);
+ $listener->preventGuestsFromJoiningIfNotPubliclyAccessible($event->getRoom());
} catch (UnauthorizedException $e) {
- $event->setArgument('cancel', true);
+ $event->setCancelJoin( true);
}
};
$dispatcher->addListener(Room::class . '::preJoinRoomGuest', $listener);
diff --git a/lib/Files/TemplateLoader.php b/lib/Files/TemplateLoader.php
index 83cba79a6..2d29bd2b9 100644
--- a/lib/Files/TemplateLoader.php
+++ b/lib/Files/TemplateLoader.php
@@ -23,15 +23,15 @@ declare(strict_types=1);
namespace OCA\Talk\Files;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Util;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Helper class to add the Talk UI to the sidebar of the Files app.
*/
class TemplateLoader {
- public static function register(EventDispatcherInterface $dispatcher): void {
+ public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener('OCA\Files::loadAdditionalScripts', static function() {
self::loadTalkSidebarForFilesApp();
});
diff --git a/lib/GuestManager.php b/lib/GuestManager.php
index d01e8dd1a..1ccd0a878 100644
--- a/lib/GuestManager.php
+++ b/lib/GuestManager.php
@@ -23,9 +23,12 @@ declare(strict_types=1);
namespace OCA\Talk;
+use OCA\Talk\Events\AddEmailEvent;
+use OCA\Talk\Events\ModifyParticipantEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -33,8 +36,6 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\Util;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class GuestManager {
@@ -56,7 +57,7 @@ class GuestManager {
/** @var IL10N */
protected $l;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
protected $dispatcher;
public function __construct(IDBConnection $connection,
@@ -65,7 +66,7 @@ class GuestManager {
IUserSession $userSession,
IURLGenerator $url,
IL10N $l,
- EventDispatcherInterface $dispatcher) {
+ IEventDispatcher $dispatcher) {
$this->connection = $connection;
$this->mailer = $mailer;
$this->defaults = $defaults;
@@ -77,12 +78,12 @@ class GuestManager {
/**
* @param Room $room
- * @param string $sessionId
+ * @param Participant $participant
* @param string $displayName
* @throws \Doctrine\DBAL\DBALException
*/
- public function updateName(Room $room, string $sessionId, string $displayName): void {
- $sessionHash = sha1($sessionId);
+ public function updateName(Room $room, Participant $participant, string $displayName): void {
+ $sessionHash = sha1($participant->getSessionId());
$dispatchEvent = true;
try {
@@ -104,12 +105,9 @@ class GuestManager {
], ['session_hash']);
}
-
if ($dispatchEvent) {
- $this->dispatcher->dispatch(self::class . '::updateName', new GenericEvent($room, [
- 'sessionId' => $sessionId,
- 'newName' => $displayName,
- ]));
+ $event = new ModifyParticipantEvent($room, $participant, 'name', $displayName);
+ $this->dispatcher->dispatch(self::class . '::updateName', $event);
}
}
@@ -162,9 +160,8 @@ class GuestManager {
}
public function inviteByEmail(Room $room, string $email): void {
- $this->dispatcher->dispatch(self::class . '::preInviteByEmail', new GenericEvent($room, [
- 'email' => $email,
- ]));
+ $event = new AddEmailEvent($room, $email);
+ $this->dispatcher->dispatch(self::class . '::preInviteByEmail', $event);
$link = $this->url->linkToRouteAbsolute('spreed.pagecontroller.showCall', ['token' => $room->getToken()]);
@@ -207,9 +204,7 @@ class GuestManager {
try {
$this->mailer->send($message);
- $this->dispatcher->dispatch(self::class . '::postInviteByEmail', new GenericEvent($room, [
- 'email' => $email,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postInviteByEmail', $event);
} catch (\Exception $e) {
}
}
diff --git a/lib/Listener.php b/lib/Listener.php
index 7d780166d..0f9304774 100644
--- a/lib/Listener.php
+++ b/lib/Listener.php
@@ -24,11 +24,11 @@ namespace OCA\Talk;
use OCP\Collaboration\AutoComplete\AutoCompleteEvent;
use OCP\Collaboration\AutoComplete\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Util;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Listener {
@@ -57,8 +57,8 @@ class Listener {
$this->config = $config;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- \OC::$server->getUserManager()->listen('\OC\User', 'postDelete', function ($user) {
+ public static function register(IEventDispatcher $dispatcher): void {
+ \OC::$server->getUserManager()->listen('\OC\User', 'postDelete', static function ($user) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->deleteUser($user);
@@ -66,7 +66,7 @@ class Listener {
Util::connectHook('OC_User', 'logout', self::class, 'logoutUserStatic');
- $dispatcher->addListener(IManager::class . '::filterResults', function(AutoCompleteEvent $event) {
+ $dispatcher->addListener(IManager::class . '::filterResults', static function(AutoCompleteEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
diff --git a/lib/Listener/RestrictStartingCalls.php b/lib/Listener/RestrictStartingCalls.php
index 1ef8ebfe3..1188215fd 100644
--- a/lib/Listener/RestrictStartingCalls.php
+++ b/lib/Listener/RestrictStartingCalls.php
@@ -23,12 +23,11 @@ declare(strict_types=1);
namespace OCA\Talk\Listener;
+use OCA\Talk\Events\ModifyParticipantEvent;
use OCA\Talk\Exceptions\ForbiddenException;
-use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class RestrictStartingCalls {
@@ -39,9 +38,8 @@ class RestrictStartingCalls {
$this->config = $config;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- $dispatcher->addListener(Room::class . '::preSessionJoinCall', function(GenericEvent $event) {
-
+ public static function register(IEventDispatcher $dispatcher): void {
+ $dispatcher->addListener(Room::class . '::preSessionJoinCall', static function(ModifyParticipantEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->checkStartCallPermissions($event);
@@ -49,16 +47,12 @@ class RestrictStartingCalls {
}
/**
- * @param GenericEvent $event
+ * @param ModifyParticipantEvent $event
* @throws ForbiddenException
*/
- public function checkStartCallPermissions(GenericEvent $event): void {
- /** @var Room $room */
- $room = $event->getSubject();
- /** @var string $sessionId */
- $sessionId = $event->getArgument('sessionId');
- /** @var Participant $participant */
- $participant = $room->getParticipantBySession($sessionId);
+ public function checkStartCallPermissions(ModifyParticipantEvent $event): void {
+ $room = $event->getRoom();
+ $participant = $event->getParticipant();
if (!$participant->canStartCall() && !$room->hasSessionsInCall()) {
throw new ForbiddenException('Can not start a call');
diff --git a/lib/Manager.php b/lib/Manager.php
index 8623e9235..8a7e01471 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -25,12 +25,15 @@ namespace OCA\Talk;
use OCA\Talk\Chat\Changelog;
use OCA\Talk\Chat\CommentsManager;
+use OCA\Talk\Events\CreateRoomTokenEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\NotFoundException;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -38,8 +41,6 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Manager {
@@ -55,7 +56,7 @@ class Manager {
private $commentsManager;
/** @var TalkSession */
private $talkSession;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var ITimeFactory */
protected $timeFactory;
@@ -70,7 +71,7 @@ class Manager {
IUserManager $userManager,
CommentsManager $commentsManager,
TalkSession $talkSession,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
ITimeFactory $timeFactory,
IHasher $hasher,
IL10N $l) {
@@ -616,7 +617,8 @@ class Manager {
$room = $this->getRoomById($roomId);
- $this->dispatcher->dispatch(Room::class . '::createRoom', new GenericEvent($room));
+ $event = new RoomEvent($room);
+ $this->dispatcher->dispatch(Room::class . '::createdRoom', $event);
return $room;
}
@@ -798,14 +800,12 @@ class Manager {
* @throws \OutOfBoundsException
*/
protected function generateNewToken(IQueryBuilder $query, int $entropy, string $chars): string {
- $event = new GenericEvent(null, [
- 'entropy' => $entropy,
- 'chars' => $chars,
- ]);
+
+ $event = new CreateRoomTokenEvent($entropy, $chars);
$this->dispatcher->dispatch(self::class . '::generateNewToken', $event);
try {
- $token = $event->getArgument('token');
- if (empty($token)) {
+ $token = $event->getToken();
+ if ($token === '') {
// Will generate default token below.
throw new \InvalidArgumentException('token may not be empty');
}
diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php
index bb55d5ccf..f272335ac 100644
--- a/lib/Notification/Listener.php
+++ b/lib/Notification/Listener.php
@@ -22,14 +22,16 @@ declare(strict_types=1);
namespace OCA\Talk\Notification;
+use OCA\Talk\Events\AddParticipantsEvent;
+use OCA\Talk\Events\JoinRoomUserEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Notification\IManager;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Listener {
@@ -52,10 +54,9 @@ class Listener {
$this->logger = $logger;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ public static function register(IEventDispatcher $dispatcher): void {
+ $listener = static function(AddParticipantsEvent $event) {
+ $room = $event->getRoom();
if ($room->getObjectType() === 'file') {
return;
@@ -63,37 +64,28 @@ class Listener {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->generateInvitation($room, $event->getArgument('users'));
+ $listener->generateInvitation($room, $event->getParticipants());
};
$dispatcher->addListener(Room::class . '::postAddUsers', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
-
+ $listener = static function(JoinRoomUserEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->markInvitationRead($room);
+ $listener->markInvitationRead($event->getRoom());
};
$dispatcher->addListener(Room::class . '::postJoinRoom', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
-
+ $listener = static function(RoomEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->generateCallNotifications($room);
+ $listener->generateCallNotifications($event->getRoom());
};
$dispatcher->addListener(Room::class . '::preSessionJoinCall', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
-
+ $listener = static function(RoomEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
- $listener->markCallNotificationsRead($room);
+ $listener->markCallNotificationsRead($event->getRoom());
};
$dispatcher->addListener(Room::class . '::postSessionJoinCall', $listener);
}
diff --git a/lib/PublicShare/TemplateLoader.php b/lib/PublicShare/TemplateLoader.php
index a3906e99c..a388e0690 100644
--- a/lib/PublicShare/TemplateLoader.php
+++ b/lib/PublicShare/TemplateLoader.php
@@ -24,10 +24,10 @@ declare(strict_types=1);
namespace OCA\Talk\PublicShare;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\FileInfo;
use OCP\Share\IShare;
use OCP\Util;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
@@ -39,7 +39,7 @@ use Symfony\Component\EventDispatcher\GenericEvent;
*/
class TemplateLoader {
- public static function register(EventDispatcherInterface $dispatcher): void {
+ public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', static function(GenericEvent $event) {
/** @var IShare $share */
$share = $event->getArgument('share');
diff --git a/lib/PublicShareAuth/Listener.php b/lib/PublicShareAuth/Listener.php
index 1c4db6587..433dc41c8 100644
--- a/lib/PublicShareAuth/Listener.php
+++ b/lib/PublicShareAuth/Listener.php
@@ -23,11 +23,13 @@ declare(strict_types=1);
namespace OCA\Talk\PublicShareAuth;
+use OCA\Talk\Events\JoinRoomGuestEvent;
+use OCA\Talk\Events\JoinRoomUserEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Participant;
use OCA\Talk\Room;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCP\EventDispatcher\IEventDispatcher;
/**
* Custom behaviour for rooms to request the password for a share.
@@ -44,25 +46,19 @@ use Symfony\Component\EventDispatcher\GenericEvent;
*/
class Listener {
- public static function register(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
- self::preventExtraUsersFromJoining($room, $event->getArgument('userId'));
+ public static function register(IEventDispatcher $dispatcher): void {
+ $listener = static function(JoinRoomUserEvent $event) {
+ self::preventExtraUsersFromJoining($event->getRoom(), $event->getUser()->getUID());
};
$dispatcher->addListener(Room::class . '::preJoinRoom', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
- self::preventExtraGuestsFromJoining($room);
+ $listener = static function(JoinRoomGuestEvent $event) {
+ self::preventExtraGuestsFromJoining($event->getRoom());
};
$dispatcher->addListener(Room::class . '::preJoinRoomGuest', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
- self::destroyRoomOnParticipantLeave($room);
+ $listener = static function(RoomEvent $event) {
+ self::destroyRoomOnParticipantLeave($event->getRoom());
};
$dispatcher->addListener(Room::class . '::postRemoveUser', $listener);
$dispatcher->addListener(Room::class . '::postRemoveBySession', $listener);
diff --git a/lib/PublicShareAuth/TemplateLoader.php b/lib/PublicShareAuth/TemplateLoader.php
index 78d278fe6..264097cd6 100644
--- a/lib/PublicShareAuth/TemplateLoader.php
+++ b/lib/PublicShareAuth/TemplateLoader.php
@@ -23,9 +23,9 @@ declare(strict_types=1);
namespace OCA\Talk\PublicShareAuth;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Share\IShare;
use OCP\Util;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
@@ -37,7 +37,7 @@ use Symfony\Component\EventDispatcher\GenericEvent;
*/
class TemplateLoader {
- public static function register(EventDispatcherInterface $dispatcher): void {
+ public static function register(IEventDispatcher $dispatcher): void {
$listener = function(GenericEvent $event) {
/** @var IShare $share */
$share = $event->getArgument('share');
diff --git a/lib/Room.php b/lib/Room.php
index 08ee9b506..821155712 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -26,18 +26,28 @@ declare(strict_types=1);
namespace OCA\Talk;
+use OCA\Talk\Events\AddParticipantsEvent;
+use OCA\Talk\Events\JoinRoomGuestEvent;
+use OCA\Talk\Events\JoinRoomUserEvent;
+use OCA\Talk\Events\ModifyLobbyEvent;
+use OCA\Talk\Events\ModifyParticipantEvent;
+use OCA\Talk\Events\ModifyRoomEvent;
+use OCA\Talk\Events\ParticipantEvent;
+use OCA\Talk\Events\RemoveParticipantEvent;
+use OCA\Talk\Events\RemoveUserEvent;
+use OCA\Talk\Events\RoomEvent;
+use OCA\Talk\Events\VerifyRoomPasswordEvent;
use OCA\Talk\Exceptions\InvalidPasswordException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Room {
public const UNKNOWN_CALL = -1;
@@ -62,7 +72,7 @@ class Room {
private $db;
/** @var ISecureRandom */
private $secureRandom;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var ITimeFactory */
private $timeFactory;
@@ -108,7 +118,7 @@ class Room {
public function __construct(Manager $manager,
IDBConnection $db,
ISecureRandom $secureRandom,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
ITimeFactory $timeFactory,
IHasher $hasher,
int $id,
@@ -296,9 +306,8 @@ class Room {
public function deleteRoom(): void {
$participants = $this->getParticipantsLegacy();
- $this->dispatcher->dispatch(self::class . '::preDeleteRoom', new GenericEvent($this, [
- 'participants' => $participants,
- ]));
+ $event = new RoomEvent($this);
+ $this->dispatcher->dispatch(self::class . '::preDeleteRoom', $event);
$query = $this->db->getQueryBuilder();
// Delete all participants
@@ -311,9 +320,7 @@ class Room {
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
- $this->dispatcher->dispatch(self::class . '::postDeleteRoom', new GenericEvent($this, [
- 'participants' => $participants,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postDeleteRoom', $event);
}
/**
@@ -326,10 +333,8 @@ class Room {
return false;
}
- $this->dispatcher->dispatch(self::class . '::preSetName', new GenericEvent($this, [
- 'newName' => $newName,
- 'oldName' => $oldName,
- ]));
+ $event = new ModifyRoomEvent($this, 'name', $newName, $oldName);
+ $this->dispatcher->dispatch(self::class . '::preSetName', $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_rooms')
@@ -338,10 +343,7 @@ class Room {
$query->execute();
$this->name = $newName;
- $this->dispatcher->dispatch(self::class . '::postSetName', new GenericEvent($this, [
- 'newName' => $newName,
- 'oldName' => $oldName,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSetName', $event);
return true;
}
@@ -357,9 +359,8 @@ class Room {
$hash = $password !== '' ? $this->hasher->hash($password) : '';
- $this->dispatcher->dispatch(self::class . '::preSetPassword', new GenericEvent($this, [
- 'password' => $password,
- ]));
+ $event = new ModifyRoomEvent($this, 'password', $password);
+ $this->dispatcher->dispatch(self::class . '::preSetPassword', $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_rooms')
@@ -368,9 +369,7 @@ class Room {
$query->execute();
$this->password = $hash;
- $this->dispatcher->dispatch(self::class . '::postSetPassword', new GenericEvent($this, [
- 'password' => $password,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSetPassword', $event);
return true;
}
@@ -449,7 +448,7 @@ class Room {
* @param int $newType Currently it is only allowed to change between `self::GROUP_CALL` and `self::PUBLIC_CALL`
* @return bool True when the change was valid, false otherwise
*/
- public function changeType(int $newType): bool {
+ public function setType(int $newType): bool {
if ($newType === $this->getType()) {
return true;
}
@@ -464,10 +463,8 @@ class Room {
$oldType = $this->getType();
- $this->dispatcher->dispatch(self::class . '::preChangeType', new GenericEvent($this, [
- 'newType' => $newType,
- 'oldType' => $oldType,
- ]));
+ $event = new ModifyRoomEvent($this, 'type', $newType, $oldType);
+ $this->dispatcher->dispatch(self::class . '::preSetType', $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_rooms')
@@ -486,10 +483,7 @@ class Room {
$query->execute();
}
- $this->dispatcher->dispatch(self::class . '::postChangeType', new GenericEvent($this, [
- 'newType' => $newType,
- 'oldType' => $oldType,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSetType', $event);
return true;
}
@@ -515,10 +509,8 @@ class Room {
return false;
}
- $this->dispatcher->dispatch(self::class . '::preSetReadOnly', new GenericEvent($this, [
- 'newState' => $newState,
- 'oldState' => $oldState,
- ]));
+ $event = new ModifyRoomEvent($this, 'readOnly', $newState, $oldState);
+ $this->dispatcher->dispatch(self::class . '::preSetReadOnly', $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_rooms')
@@ -528,10 +520,7 @@ class Room {
$this->readOnly = $newState;
- $this->dispatcher->dispatch(self::class . '::postSetReadOnly', new GenericEvent($this, [
- 'newState' => $newState,
- 'oldState' => $oldState,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSetReadOnly', $event);
return true;
}
@@ -560,12 +549,8 @@ class Room {
return false;
}
- $this->dispatcher->dispatch(self::class . '::preSetLobbyState', new GenericEvent($this, [
- 'newState' => $newState,
- 'oldState' => $oldState,
- 'lobbyTimer' => $dateTime,
- 'timerReached' => $timerReached,
- ]));
+ $event = new ModifyLobbyEvent($this, 'lobby', $newState, $oldState, $dateTime, $timerReached);
+ $this->dispatcher->dispatch(self::class . '::preSetLobbyState', $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_rooms')
@@ -576,12 +561,7 @@ class Room {
$this->lobbyState = $newState;
- $this->dispatcher->dispatch(self::class . '::postSetLobbyState', new GenericEvent($this, [
- 'newState' => $newState,
- 'oldState' => $oldState,
- 'lobbyTimer' => $dateTime,
- 'timerReached' => $timerReached,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSetLobbyState', $event);
return true;
}
@@ -606,12 +586,11 @@ class Room {
}
/**
- * @param array[] ...$participants
+ * @param array ...$participants
*/
public function addUsers(array ...$participants): void {
- $this->dispatcher->dispatch(self::class . '::preAddUsers', new GenericEvent($this, [
- 'users' => $participants,
- ]));
+ $event = new AddParticipantsEvent($this, $participants);
+ $this->dispatcher->dispatch(self::class . '::preAddUsers', $event);
$lastMessage = 0;
if ($this->getLastMessage() instanceof IComment) {
@@ -639,32 +618,25 @@ class Room {
$query->execute();
}
- $this->dispatcher->dispatch(self::class . '::postAddUsers', new GenericEvent($this, [
- 'users' => $participants,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postAddUsers', $event);
}
/**
- * @param string $participant
+ * @param Participant $participant
* @param int $participantType
*/
- public function setParticipantType(string $participant, int $participantType): void {
- $this->dispatcher->dispatch(self::class . '::preSetParticipantType', new GenericEvent($this, [
- 'user' => $participant,
- 'newType' => $participantType,
- ]));
+ public function setParticipantType(Participant $participant, int $participantType): void {
+ $event = new ModifyParticipantEvent($this, $participant, 'type', $participantType, $participant->getParticipantType());
+ $this->dispatcher->dispatch(self::class . '::preSetParticipantType', $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_participants')
->set('participant_type', $query->createNamedParameter($participantType, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
- ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($participant)));
+ ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($participant->getUser())));
$query->execute();
- $this->dispatcher->dispatch(self::class . '::postSetParticipantType', new GenericEvent($this, [
- 'user' => $participant,
- 'newType' => $participantType,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSetParticipantType', $event);
}
/**
@@ -672,10 +644,8 @@ class Room {
* @param int $participantType
*/
public function setParticipantTypeBySession(Participant $participant, int $participantType): void {
- $this->dispatcher->dispatch(self::class . '::preSetParticipantTypeBySession', new GenericEvent($this, [
- 'participant' => $participant,
- 'newType' => $participantType,
- ]));
+ $event = new ModifyParticipantEvent($this, $participant, 'type', $participantType, $participant->getParticipantType());
+ $this->dispatcher->dispatch(self::class . '::preSetParticipantTypeBySession', $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_participants')
@@ -684,10 +654,7 @@ class Room {
->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())));
$query->execute();
- $this->dispatcher->dispatch(self::class . '::postSetParticipantTypeBySession', new GenericEvent($this, [
- 'participant' => $participant,
- 'newType' => $participantType,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSetParticipantTypeBySession', $event);
}
/**
@@ -701,11 +668,8 @@ class Room {
return;
}
- $this->dispatcher->dispatch(self::class . '::preRemoveUser', new GenericEvent($this, [
- 'user' => $user,
- 'participant' => $participant,
- 'reason' => $reason,
- ]));
+ $event = new RemoveUserEvent($this, $participant, $user, $reason);
+ $this->dispatcher->dispatch(self::class . '::preRemoveUser', $event);
if ($this->getType() === self::ONE_TO_ONE_CALL) {
$this->setName($user->getUID());
@@ -717,11 +681,7 @@ class Room {
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($user->getUID())));
$query->execute();
- $this->dispatcher->dispatch(self::class . '::postRemoveUser', new GenericEvent($this, [
- 'user' => $user,
- 'participant' => $participant,
- 'reason' => $reason,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postRemoveUser', $event);
}
@@ -730,10 +690,8 @@ class Room {
* @param string $reason
*/
public function removeParticipantBySession(Participant $participant, string $reason): void {
- $this->dispatcher->dispatch(self::class . '::preRemoveBySession', new GenericEvent($this, [
- 'participant' => $participant,
- 'reason' => $reason,
- ]));
+ $event = new RemoveParticipantEvent($this, $participant, $reason);
+ $this->dispatcher->dispatch(self::class . '::preRemoveBySession', $event);
$query = $this->db->getQueryBuilder();
$query->delete('talk_participants')
@@ -741,10 +699,7 @@ class Room {
->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())));
$query->execute();
- $this->dispatcher->dispatch(self::class . '::postRemoveBySession', new GenericEvent($this, [
- 'participant' => $participant,
- 'reason' => $reason,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postRemoveBySession', $event);
}
/**
@@ -756,14 +711,10 @@ class Room {
* @throws UnauthorizedException
*/
public function joinRoom(IUser $user, string $password, bool $passedPasswordProtection = false): string {
- $event = new GenericEvent($this, [
- 'userId' => $user->getUID(),
- 'password' => $password,
- 'passedPasswordProtection' => $passedPasswordProtection,
- ]);
+ $event = new JoinRoomUserEvent($this, $user, $password, $passedPasswordProtection);
$this->dispatcher->dispatch(self::class . '::preJoinRoom', $event);
- if ($event->hasArgument('cancel') && $event->getArgument('cancel') === true) {
+ if ($event->getCancelJoin() === true) {
$this->removeUser($user, self::PARTICIPANT_LEFT);
throw new UnauthorizedException('Participant is not allowed to join');
}
@@ -779,7 +730,7 @@ class Room {
$result = $query->execute();
if ($result === 0) {
- if (!$passedPasswordProtection && !$this->verifyPassword($password)['result']) {
+ if (!$event->getPassedPasswordProtection() && !$this->verifyPassword($password)['result']) {
throw new InvalidPasswordException();
}
@@ -797,11 +748,7 @@ class Room {
$query->execute();
}
- $this->dispatcher->dispatch(self::class . '::postJoinRoom', new GenericEvent($this, [
- 'userId' => $user->getUID(),
- 'password' => $password,
- 'passedPasswordProtection' => $passedPasswordProtection,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postJoinRoom', $event);
return $sessionId;
}
@@ -817,11 +764,8 @@ class Room {
return;
}
- $this->dispatcher->dispatch(self::class . '::preUserDisconnectRoom', new GenericEvent($this, [
- 'userId' => $userId,
- 'sessionId' => $sessionId,
- 'participant' => $participant,
- ]));
+ $event = new ParticipantEvent($this, $participant);
+ $this->dispatcher->dispatch(self::class . '::preUserDisconnectRoom', $event);
// Reset session when leaving a normal room
$query = $this->db->getQueryBuilder();
@@ -845,14 +789,9 @@ class Room {
if (!empty($sessionId)) {
$query->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)));
}
- $selfJoined = (bool) $query->execute();
-
- $this->dispatcher->dispatch(self::class . '::postUserDisconnectRoom', new GenericEvent($this, [
- 'userId' => $userId,
- 'sessionId' => $sessionId,
- 'participant' => $participant,
- 'selfJoin' => $selfJoined,
- ]));
+ $query->execute();
+
+ $this->dispatcher->dispatch(self::class . '::postUserDisconnectRoom', $event);
}
/**
@@ -863,14 +802,14 @@ class Room {
* @throws UnauthorizedException
*/
public function joinRoomGuest(string $password, bool $passedPasswordProtection = false): string {
- $event = new GenericEvent($this);
+ $event = new JoinRoomGuestEvent($this, $password, $passedPasswordProtection);
$this->dispatcher->dispatch(self::class . '::preJoinRoomGuest', $event);
- if ($event->hasArgument('cancel') && $event->getArgument('cancel') === true) {
+ if ($event->getCancelJoin()) {
throw new UnauthorizedException('Participant is not allowed to join');
}
- if (!$passedPasswordProtection && !$this->verifyPassword($password)['result']) {
+ if (!$event->getPassedPasswordProtection() && !$this->verifyPassword($password)['result']) {
throw new InvalidPasswordException();
}
@@ -891,28 +830,23 @@ class Room {
$sessionId = $this->secureRandom->generate(255);
}
- $this->dispatcher->dispatch(self::class . '::postJoinRoomGuest', new GenericEvent($this));
+ $this->dispatcher->dispatch(self::class . '::postJoinRoomGuest', $event);
return $sessionId;
}
-
- public function changeInCall(string $sessionId, int $flags): void {
+ public function changeInCall(Participant $participant, int $flags): void {
+ $event = new ModifyParticipantEvent($this, $participant, 'inCall', $flags, $participant->getInCallFlags());
if ($flags !== Participant::FLAG_DISCONNECTED) {
- $this->dispatcher->dispatch(self::class . '::preSessionJoinCall', new GenericEvent($this, [
- 'sessionId' => $sessionId,
- 'flags' => $flags,
- ]));
+ $this->dispatcher->dispatch(self::class . '::preSessionJoinCall', $event);
} else {
- $this->dispatcher->dispatch(self::class . '::preSessionLeaveCall', new GenericEvent($this, [
- 'sessionId' => $sessionId,
- ]));
+ $this->dispatcher->dispatch(self::class . '::preSessionLeaveCall', $event);
}
$query = $this->db->getQueryBuilder();
$query->update('talk_participants')
->set('in_call', $query->createNamedParameter($flags, IQueryBuilder::PARAM_INT))
- ->where($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)))
+ ->where($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())))
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
if ($flags !== Participant::FLAG_DISCONNECTED) {
@@ -924,14 +858,9 @@ class Room {
$query->execute();
if ($flags !== Participant::FLAG_DISCONNECTED) {
- $this->dispatcher->dispatch(self::class . '::postSessionJoinCall', new GenericEvent($this, [
- 'sessionId' => $sessionId,
- 'flags' => $flags,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSessionJoinCall', $event);
} else {
- $this->dispatcher->dispatch(self::class . '::postSessionLeaveCall', new GenericEvent($this, [
- 'sessionId' => $sessionId,
- ]));
+ $this->dispatcher->dispatch(self::class . '::postSessionLeaveCall', $event);
}
}
@@ -940,22 +869,19 @@ class Room {
* @return array
*/
public function verifyPassword(string $password): array {
- $event = new GenericEvent($this, [
- 'password' => $password
- ]);
-
+ $event = new VerifyRoomPasswordEvent($this, $password);
$this->dispatcher->dispatch(self::class . '::verifyPassword', $event);
- if ($event->hasArgument('result')) {
- $result = $event->getArgument('result');
+
+ if ($event->isPasswordValid() !== null) {
return [
- 'result' => $result['result'] ?? false,
- 'url' => $result['url'] ?? ''
+ 'result' => $event->isPasswordValid(),
+ 'url' => $event->getRedirectUrl(),
];
}
return [
'result' => !$this->hasPassword() || $this->hasher->verify($password, $this->password),
- 'url' => ''
+ 'url' => '',
];
}
@@ -976,7 +902,8 @@ class Room {
}
public function cleanGuestParticipants(): void {
- $this->dispatcher->dispatch(self::class . '::preCleanGuests', new GenericEvent($this));
+ $event = new RoomEvent($this);
+ $this->dispatcher->dispatch(self::class . '::preCleanGuests', $event);
$query = $this->db->getQueryBuilder();
$query->delete('talk_participants')
@@ -985,7 +912,7 @@ class Room {
->andWhere($query->expr()->lte('last_ping', $query->createNamedParameter($this->timeFactory->getTime() - 100, IQueryBuilder::PARAM_INT)));
$query->execute();
- $this->dispatcher->dispatch(self::class . '::postCleanGuests', new GenericEvent($this));
+ $this->dispatcher->dispatch(self::class . '::postCleanGuests', $event);
}
/**
diff --git a/lib/Share/RoomShareProvider.php b/lib/Share/RoomShareProvider.php
index 0281ccdf5..93982b277 100644
--- a/lib/Share/RoomShareProvider.php
+++ b/lib/Share/RoomShareProvider.php
@@ -27,12 +27,17 @@ declare(strict_types=1);
namespace OCA\Talk\Share;
+use OCA\Talk\Events\ParticipantEvent;
+use OCA\Talk\Events\RemoveUserEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
+use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCP\Files\Node;
use OCP\IDBConnection;
@@ -94,32 +99,29 @@ class RoomShareProvider implements IShareProvider {
$this->l = $l;
}
- public static function register(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ public static function register(IEventDispatcher $dispatcher): void {
+ $listener = static function(ParticipantEvent $event) {
+ $room = $event->getRoom();
- if ($event->getArgument('selfJoin')) {
+ if ($event->getParticipant()->getParticipantType() === Participant::USER_SELF_JOINED) {
/** @var self $roomShareProvider */
$roomShareProvider = \OC::$server->query(self::class);
- $roomShareProvider->deleteInRoom($room->getToken(), $event->getArgument('userId'));
+ $roomShareProvider->deleteInRoom($room->getToken(), $event->getParticipant()->getUser());
}
};
$dispatcher->addListener(Room::class . '::postUserDisconnectRoom', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $listener = static function(RemoveUserEvent $event) {
+ $room = $event->getRoom();
/** @var self $roomShareProvider */
$roomShareProvider = \OC::$server->query(self::class);
- $roomShareProvider->deleteInRoom($room->getToken(), $event->getArgument('user')->getUID());
+ $roomShareProvider->deleteInRoom($room->getToken(), $event->getUser()->getUID());
};
$dispatcher->addListener(Room::class . '::postRemoveUser', $listener);
- $listener = function(GenericEvent $event) {
- /** @var Room $room */
- $room = $event->getSubject();
+ $listener = static function(RoomEvent $event) {
+ $room = $event->getRoom();
/** @var self $roomShareProvider */
$roomShareProvider = \OC::$server->query(self::class);
@@ -166,6 +168,7 @@ class RoomShareProvider implements IShareProvider {
$existingShares = $this->getSharesByPath($share->getNode());
foreach ($existingShares as $existingShare) {
if ($existingShare->getSharedWith() === $share->getSharedWith()) {
+ // FIXME Should be moved away from GenericEvent as soon as OCP\Share20\IManager did move too
$this->dispatcher->dispatch(self::class . '::' . 'share_file_again', new GenericEvent($existingShare));
throw new GenericShareException('Already shared', $this->l->t('Path is already shared with this room'), 403);
}
diff --git a/lib/Signaling/Listener.php b/lib/Signaling/Listener.php
index 2f173b35b..86274ecee 100644
--- a/lib/Signaling/Listener.php
+++ b/lib/Signaling/Listener.php
@@ -24,16 +24,24 @@ namespace OCA\Talk\Signaling;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Config;
+use OCA\Talk\Events\AddParticipantsEvent;
+use OCA\Talk\Events\ChatEvent;
+use OCA\Talk\Events\ChatParticipantEvent;
+use OCA\Talk\Events\ModifyLobbyEvent;
+use OCA\Talk\Events\ModifyParticipantEvent;
+use OCA\Talk\Events\ModifyRoomEvent;
+use OCA\Talk\Events\ParticipantEvent;
+use OCA\Talk\Events\RemoveParticipantEvent;
+use OCA\Talk\Events\RemoveUserEvent;
+use OCA\Talk\Events\RoomEvent;
use OCA\Talk\GuestManager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
-use OCP\IUser;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCP\EventDispatcher\IEventDispatcher;
class Listener {
- public static function register(EventDispatcherInterface $dispatcher): void {
+ public static function register(IEventDispatcher $dispatcher): void {
self::registerInternalSignaling($dispatcher);
self::registerExternalSignaling($dispatcher);
}
@@ -44,18 +52,15 @@ class Listener {
return empty($config->getSignalingServers());
}
- protected static function registerInternalSignaling(EventDispatcherInterface $dispatcher): void {
- $listener = function(GenericEvent $event) {
+ protected static function registerInternalSignaling(IEventDispatcher $dispatcher): void {
+ $listener = static function(RoomEvent $event) {
if (!self::isUsingInternalSignaling()) {
return;
}
- /** @var Room $room */
- $room = $event->getSubject();
-
/** @var Messages $messages */
$messages = \OC::$server->query(Messages::class);
- $messages->addMessageForAllParticipants($room, 'refresh-participant-list');
+ $messages->addMessageForAllParticipants($event->getRoom(), 'refresh-participant-list');
};
$dispatcher->addListener(Room::class . '::postJoinRoom', $listener);
$dispatcher->addListener(Room::class . '::postJoinRoomGuest', $listener);
@@ -63,13 +68,12 @@ class Listener {
$dispatcher->addListener(Room::class . '::postSessionLeaveCall', $listener);
$dispatcher->addListener(GuestManager::class . '::updateName', $listener);
- $listener = function(GenericEvent $event) {
+ $listener = static function(ParticipantEvent $event) {
if (!self::isUsingInternalSignaling()) {
return;
}
- /** @var Room $room */
- $room = $event->getSubject();
+ $room = $event->getRoom();
/** @var Messages $messages */
$messages = \OC::$server->query(Messages::class);
@@ -79,7 +83,7 @@ class Listener {
// no longer in the room, so the message needs to be explicitly
// added for the participant.
/** @var Participant $participant */
- $participant = $event->getArgument('participant');
+ $participant = $event->getParticipant();
if ($participant->getSessionId() !== '0') {
$messages->addMessage($participant->getSessionId(), $participant->getSessionId(), 'refresh-participant-list');
}
@@ -88,14 +92,15 @@ class Listener {
$dispatcher->addListener(Room::class . '::postRemoveBySession', $listener);
$dispatcher->addListener(Room::class . '::postUserDisconnectRoom', $listener);
- $listener = function(GenericEvent $event) {
+ $listener = static function(RoomEvent $event) {
+ $room = $event->getRoom();
if (!self::isUsingInternalSignaling()) {
return;
}
/** @var Messages $messages */
$messages = \OC::$server->query(Messages::class);
- $participants = $event->getArgument('participants');
+ $participants = $room->getParticipantsLegacy();
foreach ($participants['users'] as $participant) {
$messages->addMessage($participant['sessionId'], $participant['sessionId'], 'refresh-participant-list');
}
@@ -103,11 +108,11 @@ class Listener {
$messages->addMessage($participant['sessionId'], $participant['sessionId'], 'refresh-participant-list');
}
};
- $dispatcher->addListener(Room::class . '::postDeleteRoom', $listener);
+ $dispatcher->addListener(Room::class . '::preDeleteRoom', $listener);
}
- protected static function registerExternalSignaling(EventDispatcherInterface $dispatcher): void {
- $dispatcher->addListener(Room::class . '::postAddUsers', function(GenericEvent $event) {
+ protected static function registerExternalSignaling(IEventDispatcher $dispatcher): void {
+ $dispatcher->addListener(Room::class . '::postAddUsers', static function(AddParticipantsEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -115,11 +120,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $participants= $event->getArgument('users');
- $notifier->roomInvited($room, $participants);
+ $notifier->roomInvited($event->getRoom(), $event->getParticipants());
});
- $dispatcher->addListener(Room::class . '::postSetName', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postSetName', static function(ModifyRoomEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -127,10 +130,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $notifier->roomModified($room);
+ $notifier->roomModified($event->getRoom());
});
- $dispatcher->addListener(Room::class . '::postSetPassword', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postSetPassword', static function(ModifyRoomEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -138,10 +140,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $notifier->roomModified($room);
+ $notifier->roomModified($event->getRoom());
});
- $dispatcher->addListener(Room::class . '::postChangeType', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postSetType', static function(ModifyRoomEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -149,10 +150,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $notifier->roomModified($room);
+ $notifier->roomModified($event->getRoom());
});
- $dispatcher->addListener(Room::class . '::postSetReadOnly', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postSetReadOnly', static function(ModifyRoomEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -160,10 +160,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $notifier->roomModified($room);
+ $notifier->roomModified($event->getRoom());
});
- $dispatcher->addListener(Room::class . '::postSetLobbyState', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postSetLobbyState', static function(ModifyLobbyEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -171,10 +170,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $notifier->roomModified($room);
+ $notifier->roomModified($event->getRoom());
});
- $dispatcher->addListener(Room::class . '::postSetParticipantType', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postSetParticipantType', static function(ModifyParticipantEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -182,12 +180,11 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
// The type of a participant has changed, notify all participants
// so they can update the room properties.
- $notifier->roomModified($room);
+ $notifier->roomModified($event->getRoom());
});
- $dispatcher->addListener(Room::class . '::postSetParticipantTypeBySession', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postSetParticipantTypeBySession', static function(ModifyParticipantEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -195,12 +192,11 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
// The type of a participant has changed, notify all participants
// so they can update the room properties.
- $notifier->roomModified($room);
+ $notifier->roomModified($event->getRoom());
});
- $dispatcher->addListener(Room::class . '::postDeleteRoom', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::preDeleteRoom', static function(RoomEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -208,11 +204,11 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $participants = $event->getArgument('participants');
+ $room = $event->getRoom();
+ $participants = $room->getParticipantsLegacy();
$notifier->roomDeleted($room, $participants);
});
- $dispatcher->addListener(Room::class . '::postRemoveUser', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postRemoveUser', static function(RemoveUserEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -220,11 +216,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $user = $event->getArgument('user');
- $notifier->roomsDisinvited($room, [$user->getUID()]);
+ $notifier->roomsDisinvited($event->getRoom(), [$event->getUser()->getUID()]);
});
- $dispatcher->addListener(Room::class . '::postRemoveBySession', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postRemoveBySession', static function(RemoveParticipantEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -232,24 +226,10 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $participant = $event->getArgument('participant');
- $notifier->roomSessionsRemoved($room, [$participant->getSessionId()]);
+ $notifier->roomSessionsRemoved($event->getRoom(), [$event->getParticipant()->getSessionId()]);
});
- $dispatcher->addListener(Room::class . '::postSessionJoinCall', function(GenericEvent $event) {
- if (self::isUsingInternalSignaling()) {
- return;
- }
- /** @var BackendNotifier $notifier */
- $notifier = \OC::$server->query(BackendNotifier::class);
-
- $room = $event->getSubject();
- $sessionId = $event->getArgument('sessionId');
- $flags = $event->getArgument('flags');
- $notifier->roomInCallChanged($room, $flags, [$sessionId]);
- });
- $dispatcher->addListener(Room::class . '::postSessionLeaveCall', function(GenericEvent $event) {
+ $listener = static function(ModifyParticipantEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -257,23 +237,16 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $sessionId = $event->getArgument('sessionId');
- $notifier->roomInCallChanged($room, Participant::FLAG_DISCONNECTED, [$sessionId]);
- });
- $dispatcher->addListener(Room::class . '::postRemoveBySession', function(GenericEvent $event) {
- if (self::isUsingInternalSignaling()) {
- return;
- }
-
- /** @var BackendNotifier $notifier */
- $notifier = \OC::$server->query(BackendNotifier::class);
+ $notifier->roomInCallChanged(
+ $event->getRoom(),
+ $event->getNewValue(),
+ [$event->getParticipant()->getSessionId()]
+ );
+ };
+ $dispatcher->addListener(Room::class . '::postSessionJoinCall', $listener);
+ $dispatcher->addListener(Room::class . '::postSessionLeaveCall', $listener);
- $room = $event->getSubject();
- $participant = $event->getArgument('participant');
- $notifier->participantsModified($room, [$participant->getSessionId()]);
- });
- $dispatcher->addListener(Room::class . '::postCleanGuests', function(GenericEvent $event) {
+ $dispatcher->addListener(Room::class . '::postCleanGuests', static function(RoomEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -281,13 +254,12 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
// TODO: The list of removed session ids should be passed through the event
// so the signaling server can optimize forwarding the message.
$sessionIds = [];
- $notifier->participantsModified($room, $sessionIds);
+ $notifier->participantsModified($event->getRoom(), $sessionIds);
});
- $dispatcher->addListener(GuestManager::class . '::updateName', function(GenericEvent $event) {
+ $dispatcher->addListener(GuestManager::class . '::updateName', static function(ModifyParticipantEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -295,11 +267,9 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
- $sessionId = $event->getArgument('sessionId');
- $notifier->participantsModified($room, [$sessionId]);
+ $notifier->participantsModified($event->getRoom(), [$event->getParticipant()->getSessionId()]);
});
- $dispatcher->addListener(ChatManager::class . '::sendMessage', function(GenericEvent $event) {
+ $dispatcher->addListener(ChatManager::class . '::postSendMessage', static function(ChatParticipantEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -307,7 +277,7 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
+ $room = $event->getRoom();
$message = [
'type' => 'chat',
'chat' => [
@@ -316,7 +286,7 @@ class Listener {
];
$notifier->sendRoomMessage($room, $message);
});
- $dispatcher->addListener(ChatManager::class . '::sendSystemMessage', function(GenericEvent $event) {
+ $dispatcher->addListener(ChatManager::class . '::postSendSystemMessage', static function(ChatEvent $event) {
if (self::isUsingInternalSignaling()) {
return;
}
@@ -324,7 +294,7 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
- $room = $event->getSubject();
+ $room = $event->getRoom();
$message = [
'type' => 'chat',
'chat' => [
diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php
index 647f5a317..4e20e31a6 100644
--- a/tests/php/Chat/ChatManagerTest.php
+++ b/tests/php/Chat/ChatManagerTest.php
@@ -31,16 +31,16 @@ use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class ChatManagerTest extends TestCase {
/** @var CommentsManager|ICommentsManager|MockObject */
protected $commentsManager;
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
/** @var Notifier|MockObject */
protected $notifier;
@@ -53,7 +53,7 @@ class ChatManagerTest extends TestCase {
parent::setUp();
$this->commentsManager = $this->createMock(CommentsManager::class);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->notifier = $this->createMock(Notifier::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
diff --git a/tests/php/Chat/Command/ExecutorTest.php b/tests/php/Chat/Command/ExecutorTest.php
index 9b449123a..f935a46b0 100644
--- a/tests/php/Chat/Command/ExecutorTest.php
+++ b/tests/php/Chat/Command/ExecutorTest.php
@@ -25,20 +25,21 @@ namespace OCA\Talk\Tests\php\Chat\Command;
use OCA\Talk\Chat\Command\Executor;
use OCA\Talk\Chat\Command\ShellExecutor;
+use OCA\Talk\Events\CommandEvent;
use OCA\Talk\Model\Command;
use OCA\Talk\Room;
use OCA\Talk\Service\CommandService;
use OCP\Comments\IComment;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
class ExecutorTest extends TestCase {
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
/** @var ShellExecutor|MockObject */
@@ -59,7 +60,7 @@ class ExecutorTest extends TestCase {
public function setUp(): void {
parent::setUp();
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->shellExecutor = $this->createMock(ShellExecutor::class);
$this->commandService = $this->createMock(CommandService::class);
$this->logger = $this->createMock(ILogger::class);
@@ -90,18 +91,9 @@ class ExecutorTest extends TestCase {
$room = $this->createMock(Room::class);
$command = Command::fromParams([]);
- $event = $this->createMock(GenericEvent::class);
+ $event = $this->createMock(CommandEvent::class);
$event->expects($this->once())
- ->method('setArguments')
- ->with([
- 'room' => $room,
- 'message' => $message,
- 'arguments' => $arguments,
- 'output' => '',
- ]);
- $event->expects($this->once())
- ->method('getArgument')
- ->with('output')
+ ->method('getOutput')
->willReturn($expected);
$executor = $this->getMockBuilder(Executor::class)
@@ -116,7 +108,7 @@ class ExecutorTest extends TestCase {
->getMock();
$executor->expects($this->once())
->method('createEvent')
- ->with($command)
+ ->with($room, $message, $command, $arguments)
->willReturn($event);
$this->dispatcher->expects($this->once())
diff --git a/tests/php/Chat/Command/ShellExecutorTest.php b/tests/php/Chat/Command/ShellExecutorTest.php
index 74c8978ce..21bf37503 100644
--- a/tests/php/Chat/Command/ShellExecutorTest.php
+++ b/tests/php/Chat/Command/ShellExecutorTest.php
@@ -23,39 +23,11 @@
namespace OCA\Talk\Tests\php\Chat\Command;
-use OCA\Talk\Chat\Command\Executor;
use OCA\Talk\Chat\Command\ShellExecutor;
-use OCA\Talk\Model\Command;
-use OCA\Talk\Room;
-use OCA\Talk\Service\CommandService;
-use OCP\Comments\IComment;
-use OCP\IL10N;
-use OCP\ILogger;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
class ShellExecutorTest extends TestCase {
- /** @var EventDispatcherInterface|MockObject */
- protected $dispatcher;
-
- /** @var ShellExecutor|MockObject */
- protected $shellExecutor;
-
- /** @var CommandService|MockObject */
- protected $commandService;
-
- /** @var ILogger|MockObject */
- protected $logger;
-
- /** @var IL10N|MockObject */
- protected $l10n;
-
- /** @var Executor */
- protected $executor;
-
public function dataExecShell(): array {
return [
['admin', 'token', '', '', '', ''],
diff --git a/tests/php/Controller/RoomControllerTest.php b/tests/php/Controller/RoomControllerTest.php
index 66a93e329..d31226bec 100644
--- a/tests/php/Controller/RoomControllerTest.php
+++ b/tests/php/Controller/RoomControllerTest.php
@@ -36,12 +36,12 @@ use OCA\Talk\TalkSession;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class RoomControllerTest extends \Test\TestCase {
@@ -59,7 +59,7 @@ class RoomControllerTest extends \Test\TestCase {
protected $chatManager;
/** @var GuestManager|MockObject */
protected $guestManager;
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
/** @var MessageParser|MockObject */
protected $messageParser;
@@ -79,7 +79,7 @@ class RoomControllerTest extends \Test\TestCase {
$this->manager = $this->createMock(Manager::class);
$this->guestManager = $this->createMock(GuestManager::class);
$this->chatManager = $this->createMock(ChatManager::class);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->l = $this->createMock(IL10N::class);
diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php
index 24cb9ffdf..fbb0103c6 100644
--- a/tests/php/Controller/SignalingControllerTest.php
+++ b/tests/php/Controller/SignalingControllerTest.php
@@ -25,6 +25,7 @@ namespace OCA\Talk\Tests\php\Controller;
use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Config;
use OCA\Talk\Controller\SignalingController;
+use OCA\Talk\Events\SignalingEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
@@ -33,6 +34,7 @@ use OCA\Talk\Room;
use OCA\Talk\Signaling\Messages;
use OCA\Talk\TalkSession;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IL10N;
@@ -41,7 +43,6 @@ use OCP\IUserManager;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class CustomInputSignalingController extends SignalingController {
@@ -81,7 +82,7 @@ class SignalingControllerTest extends \Test\TestCase {
private $userId;
/** @var ISecureRandom */
private $secureRandom;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var CustomInputSignalingController */
@@ -107,7 +108,7 @@ class SignalingControllerTest extends \Test\TestCase {
$this->messages = $this->createMock(Messages::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->dispatcher = \OC::$server->getEventDispatcher();
+ $this->dispatcher = \OC::$server->query(IEventDispatcher::class);
$this->recreateSignalingController();
}
@@ -531,9 +532,9 @@ class SignalingControllerTest extends \Test\TestCase {
}
public function testBackendRoomSessionFromEvent() {
- $this->dispatcher->addListener(SignalingController::class . '::signalingBackendRoom', function(GenericEvent $event) {
- $room = $event->getSubject();
- $event->setArgument('roomSession', [
+ $this->dispatcher->addListener(SignalingController::class . '::signalingBackendRoom', static function(SignalingEvent $event) {
+ $room = $event->getRoom();
+ $event->setSession([
'foo' => 'bar',
'room' => $room->getToken(),
]);
@@ -693,7 +694,7 @@ class SignalingControllerTest extends \Test\TestCase {
// Make sure that leaving a user with an old session id doesn't remove
// the current user from the room if he re-joined in the meantime.
$dbConnection = \OC::$server->getDatabaseConnection();
- $dispatcher = \OC::$server->getEventDispatcher();
+ $dispatcher = \OC::$server->query(IEventDispatcher::class);
$this->manager = new Manager(
$dbConnection,
\OC::$server->getConfig(),
diff --git a/tests/php/PasswordVerificationTest.php b/tests/php/RoomTest.php
index 212d86242..0f2ddfb5d 100644
--- a/tests/php/PasswordVerificationTest.php
+++ b/tests/php/RoomTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Peter Edens <petere@conceiva.com>
*
@@ -20,40 +21,46 @@
*/
namespace OCA\Talk\Tests\php;
+use OC\EventDispatcher\EventDispatcher;
+use OCA\Talk\Events\VerifyRoomPasswordEvent;
use OCA\Talk\Manager;
use OCA\Talk\Room;
use OCA\Talk\Webinary;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
+use OCP\ILogger;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
-use Symfony\Component\EventDispatcher\EventDispatcher;
use Test\TestCase;
-use Symfony\Component\EventDispatcher\GenericEvent;
-class PasswordVerificationTest extends TestCase {
+class RoomTest extends TestCase {
public function testVerifyPassword() {
- $dispatcher = new EventDispatcher();
- $dispatcher->addListener(Room::class . '::verifyPassword', function(GenericEvent $event) {
- $password = $event->getArgument('password');
+ $dispatcher = new EventDispatcher(
+ new \Symfony\Component\EventDispatcher\EventDispatcher(),
+ \OC::$server,
+ $this->createMock(ILogger::class)
+ );
+ $dispatcher->addListener(Room::class . '::verifyPassword', static function(VerifyRoomPasswordEvent $event) {
+ $password = $event->getPassword();
if ($password === '1234') {
- $event->setArgument('result', [ 'result' => true, 'url' => '']);
+ $event->setIsPasswordValid(true);
+ $event->setRedirectUrl('');
}
else {
- $event->setArgument('result', [ 'result' => false, 'url' => 'https://test']);
+ $event->setIsPasswordValid(false);
+ $event->setRedirectUrl('https://test');
}
});
- $hasher = $this->createMock(IHasher::class);
$room = new Room(
$this->createMock(Manager::class),
$this->createMock(IDBConnection::class),
$this->createMock(ISecureRandom::class),
$dispatcher,
$this->createMock(ITimeFactory::class),
- $hasher,
+ $this->createMock(IHasher::class),
1,
Room::PUBLIC_CALL,
Room::READ_WRITE,
diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php
index 0dcc9c61b..f73653e52 100644
--- a/tests/php/Signaling/BackendNotifierTest.php
+++ b/tests/php/Signaling/BackendNotifierTest.php
@@ -32,6 +32,7 @@ use OCA\Talk\Signaling\BackendNotifier;
use OCA\Talk\TalkSession;
use OCA\Talk\Webinary;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Http\Client\IClientService;
use OCP\IGroupManager;
use OCP\IL10N;
@@ -124,7 +125,7 @@ class BackendNotifierTest extends \Test\TestCase {
});
$dbConnection = \OC::$server->getDatabaseConnection();
- $dispatcher = \OC::$server->getEventDispatcher();
+ $dispatcher = \OC::$server->query(IEventDispatcher::class);
$this->manager = new Manager(
$dbConnection,
$config,
@@ -281,7 +282,7 @@ class BackendNotifierTest extends \Test\TestCase {
public function testRoomTypeChanged() {
$room = $this->manager->createPublicRoom();
- $room->changeType(Room::GROUP_CALL);
+ $room->setType(Room::GROUP_CALL);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {
@@ -370,7 +371,8 @@ class BackendNotifierTest extends \Test\TestCase {
'userId' => $this->userId,
'sessionId' => $userSession,
]);
- $room->changeInCall($userSession, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
+ $participant = $room->getParticipantBySession($userSession);
+ $room->changeInCall($participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {
@@ -403,7 +405,8 @@ class BackendNotifierTest extends \Test\TestCase {
$this->controller->clearRequests();
$guestSession = $room->joinRoomGuest('');
- $room->changeInCall($guestSession, Participant::FLAG_IN_CALL);
+ $guestParticipant = $room->getParticipantBySession($guestSession);
+ $room->changeInCall($guestParticipant, Participant::FLAG_IN_CALL);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {
@@ -440,7 +443,7 @@ class BackendNotifierTest extends \Test\TestCase {
], $bodies);
$this->controller->clearRequests();
- $room->changeInCall($userSession, Participant::FLAG_DISCONNECTED);
+ $room->changeInCall($participant, Participant::FLAG_DISCONNECTED);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {