From b57f32b8bbadec59df2de1b45229b5ff92c4ab5b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Jul 2023 18:26:45 +0200 Subject: [PATCH 1/3] fix: Stop using Symfony event dispatcher directly Signed-off-by: Joas Schilling --- lib/AppInfo/Application.php | 2 +- lib/Chat/SystemMessage/Listener.php | 25 ++++++------------- lib/Share/Listener.php | 11 ++++---- psalm.xml | 2 -- ...Component_EventDispatcher_GenericEvent.php | 8 ------ 5 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 tests/stubs/Symfony_Component_EventDispatcher_GenericEvent.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 66ef2929cb3..7497254e258 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -206,7 +206,7 @@ protected function registerCollaborationResourceProvider(IServerContainer $serve /** @var IProviderManager $resourceManager */ $resourceManager = $server->get(IProviderManager::class); $resourceManager->registerResourceProvider(ConversationProvider::class); - $server->getEventDispatcher()->addListener(LoadAdditionalScriptsEvent::class, static function () { + $server->get(IEventDispatcher::class)->addListener(LoadAdditionalScriptsEvent::class, static function () { Util::addScript(self::APP_ID, 'talk-collections'); }); } diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php index 5c30c474e15..d6a4c0cde2b 100644 --- a/lib/Chat/SystemMessage/Listener.php +++ b/lib/Chat/SystemMessage/Listener.php @@ -54,8 +54,9 @@ use OCP\IUser; use OCP\IUserSession; use OCP\Server; +use OCP\Share\Events\BeforeShareCreatedEvent; +use OCP\Share\Events\ShareCreatedEvent; use OCP\Share\IShare; -use Symfony\Component\EventDispatcher\GenericEvent; /** * @template-implements IEventListener @@ -86,8 +87,8 @@ public static function register(IEventDispatcher $dispatcher): void { $dispatcher->addListener(Room::EVENT_AFTER_USERS_ADD, self::class . '::addSystemMessageUserAdded'); $dispatcher->addListener(Room::EVENT_AFTER_USER_REMOVE, self::class . '::sendSystemMessageUserRemoved'); $dispatcher->addListener(Room::EVENT_AFTER_PARTICIPANT_TYPE_SET, self::class . '::sendSystemMessageAboutPromoteOrDemoteModerator'); - $dispatcher->addListener('OCP\Share::preShare', self::class . '::setShareExpiration'); - $dispatcher->addListener('OCP\Share::postShare', self::class . '::fixMimeTypeOfVoiceMessage'); + $dispatcher->addListener(BeforeShareCreatedEvent::class, self::class . '::setShareExpiration'); + $dispatcher->addListener(ShareCreatedEvent::class, self::class . '::fixMimeTypeOfVoiceMessage'); $dispatcher->addListener(RoomShareProvider::EVENT_SHARE_FILE_AGAIN, self::class . '::fixMimeTypeOfVoiceMessage'); $dispatcher->addListener(Room::EVENT_AFTER_SET_MESSAGE_EXPIRATION, self::class . '::afterSetMessageExpiration'); $dispatcher->addListener(Room::EVENT_AFTER_SET_CALL_RECORDING, self::class . '::setCallRecording'); @@ -330,13 +331,8 @@ public static function sendSystemMessageAboutPromoteOrDemoteModerator(ModifyPart } } - /** - * @param GenericEvent|Event $event - * @return void - */ - public static function setShareExpiration($event): void { - /** @var IShare $share */ - $share = $event->getSubject(); + public static function setShareExpiration(BeforeShareCreatedEvent $event): void { + $share = $event->getShare(); if ($share->getShareType() !== IShare::TYPE_ROOM) { return; @@ -357,13 +353,8 @@ public static function setShareExpiration($event): void { $share->setExpirationDate($dateTime); } - /** - * @param GenericEvent|Event $event - * @return void - */ - public static function fixMimeTypeOfVoiceMessage($event): void { - /** @var IShare $share */ - $share = $event->getSubject(); + public static function fixMimeTypeOfVoiceMessage(ShareCreatedEvent $event): void { + $share = $event->getShare(); if ($share->getShareType() !== IShare::TYPE_ROOM) { return; diff --git a/lib/Share/Listener.php b/lib/Share/Listener.php index d8e37bdc886..6af586f8a6b 100644 --- a/lib/Share/Listener.php +++ b/lib/Share/Listener.php @@ -27,20 +27,20 @@ use OCA\Talk\Config; use OCP\EventDispatcher\IEventDispatcher; use OCP\Server; +use OCP\Share\Events\BeforeShareCreatedEvent; use OCP\Share\Events\VerifyMountPointEvent; use OCP\Share\IShare; -use Symfony\Component\EventDispatcher\GenericEvent; class Listener { public static function register(IEventDispatcher $dispatcher): void { /** * @psalm-suppress UndefinedClass */ - $dispatcher->addListener('OCP\Share::preShare', [self::class, 'listenPreShare'], 1000); + $dispatcher->addListener(BeforeShareCreatedEvent::class, [self::class, 'listenPreShare'], 1000); $dispatcher->addListener(VerifyMountPointEvent::class, [self::class, 'listenVerifyMountPointEvent'], 1000); } - public static function listenPreShare(GenericEvent $event): void { + public static function listenPreShare(BeforeShareCreatedEvent $event): void { $listener = Server::get(self::class); $listener->overwriteShareTarget($event); } @@ -55,9 +55,8 @@ public function __construct( ) { } - public function overwriteShareTarget(GenericEvent $event): void { - /** @var IShare $share */ - $share = $event->getSubject(); + public function overwriteShareTarget(BeforeShareCreatedEvent $event): void { + $share = $event->getShare(); if ($share->getShareType() !== IShare::TYPE_ROOM && $share->getShareType() !== RoomShareProvider::SHARE_TYPE_USERROOM) { diff --git a/psalm.xml b/psalm.xml index d4a337ffcc8..1f7b4af5b11 100644 --- a/psalm.xml +++ b/psalm.xml @@ -61,7 +61,6 @@ - @@ -87,6 +86,5 @@ - diff --git a/tests/stubs/Symfony_Component_EventDispatcher_GenericEvent.php b/tests/stubs/Symfony_Component_EventDispatcher_GenericEvent.php deleted file mode 100644 index b6dac274f26..00000000000 --- a/tests/stubs/Symfony_Component_EventDispatcher_GenericEvent.php +++ /dev/null @@ -1,8 +0,0 @@ - Date: Fri, 4 Aug 2023 14:47:42 +0200 Subject: [PATCH 2/3] fix(CI): Bump nextcloud/ocp package for psalm Signed-off-by: Joas Schilling --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 228a77ce90a..25f481af54f 100644 --- a/composer.lock +++ b/composer.lock @@ -134,12 +134,12 @@ "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "13aca78b1a060e2e2274e660b6954597e13a7035" + "reference": "7840fe73084751b843b69d263b4ba70e59c63750" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/13aca78b1a060e2e2274e660b6954597e13a7035", - "reference": "13aca78b1a060e2e2274e660b6954597e13a7035", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/7840fe73084751b843b69d263b4ba70e59c63750", + "reference": "7840fe73084751b843b69d263b4ba70e59c63750", "shasum": "" }, "require": { @@ -171,7 +171,7 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/master" }, - "time": "2023-07-29T00:34:58+00:00" + "time": "2023-08-04T12:45:05+00:00" }, { "name": "psr/clock", From 982df1c53817ee8d8e2b0df8eecacfc58f7221e1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 4 Aug 2023 14:56:19 +0200 Subject: [PATCH 3/3] fix(CI): Update psalm baseline Signed-off-by: Joas Schilling --- tests/psalm-baseline.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 441c1978c87..eb29642983f 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,5 +1,5 @@ - + BeforeTemplateRenderedEvent @@ -236,9 +236,6 @@ - - - getView()]]> getView()]]>