]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update shipped implementations of the INotifier
authorJoas Schilling <coding@schilljs.com>
Tue, 30 Apr 2019 12:29:30 +0000 (14:29 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 15 Jul 2019 13:15:00 +0000 (15:15 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/comments/lib/AppInfo/Application.php
apps/comments/lib/Notification/Notifier.php
apps/updatenotification/lib/AppInfo/Application.php
apps/updatenotification/lib/Notification/Notifier.php
apps/user_ldap/appinfo/app.php
apps/user_ldap/lib/Notification/Notifier.php

index b44c1c519c836ec06c4ab34f3e155160a329b68c..3d20cbbc1690204ab2bcfd1ee09c3fbdf627b9f4 100644 (file)
@@ -76,15 +76,7 @@ class Application extends App {
        }
 
        protected function registerNotifier() {
-               $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(
-                       function() {
-                               return $this->getContainer()->query(Notifier::class);
-                       },
-                       function () {
-                               $l = $this->getContainer()->getServer()->getL10NFactory()->get('comments');
-                               return ['id' => 'comments', 'name' => $l->t('Comments')];
-                       }
-               );
+               $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(Notifier::class);
        }
 
        protected function registerCommentsEventHandler() {
index 2132f05ef884a464136ee3920ccca0c2c2ddb4a7..e8a7ade820d3d5fd070527e96f48c4d673eaed0e 100644 (file)
@@ -32,6 +32,7 @@ use OCP\IURLGenerator;
 use OCP\IUser;
 use OCP\IUserManager;
 use OCP\L10N\IFactory;
+use OCP\Notification\AlreadyProcessedException;
 use OCP\Notification\INotification;
 use OCP\Notification\INotifier;
 
@@ -66,13 +67,35 @@ class Notifier implements INotifier {
                $this->userManager = $userManager;
        }
 
+       /**
+        * Identifier of the notifier, only use [a-z0-9_]
+        *
+        * @return string
+        * @since 17.0.0
+        */
+       public function getID(): string {
+               return 'comments';
+       }
+
+       /**
+        * Human readable name describing the notifier
+        *
+        * @return string
+        * @since 17.0.0
+        */
+       public function getName(): string {
+               return $this->l10nFactory->get('comments')->t('Comments');
+       }
+
        /**
         * @param INotification $notification
         * @param string $languageCode The code of the language that should be used to prepare the notification
         * @return INotification
         * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+        * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
+        * @since 9.0.0
         */
-       public function prepare(INotification $notification, $languageCode) {
+       public function prepare(INotification $notification, string $languageCode): INotification {
                if($notification->getApp() !== 'comments') {
                        throw new \InvalidArgumentException();
                }
@@ -101,7 +124,7 @@ class Notifier implements INotifier {
                                $userFolder = $this->rootFolder->getUserFolder($notification->getUser());
                                $nodes = $userFolder->getById((int)$parameters[1]);
                                if(empty($nodes)) {
-                                       throw new \InvalidArgumentException('Cannot resolve file ID to node instance');
+                                       throw new AlreadyProcessedException();
                                }
                                $node = $nodes[0];
 
index 14512bae8385345a8bff48c1735eb91d3e50f408..91b9020d82e347f555d5f8e538b12a9d3963b2c5 100644 (file)
@@ -71,14 +71,6 @@ class Application extends App {
 
        public function registerNotifier() {
                $notificationsManager = $this->getContainer()->getServer()->getNotificationManager();
-               $notificationsManager->registerNotifier(function() {
-                       return  $this->getContainer()->query(Notifier::class);
-               }, function() {
-                       $l = $this->getContainer()->getServer()->getL10N('updatenotification');
-                       return [
-                               'id' => 'updatenotification',
-                               'name' => $l->t('Update notifications'),
-                       ];
-               });
+               $notificationsManager->registerNotifier(Notifier::class);
        }
 }
index 4e3a30f225e0a942fd72b627af0d289c12fc5f57..44fe91c63d520b3227bdc23e5952cfdd3f060ad4 100644 (file)
@@ -31,6 +31,7 @@ use OCP\IURLGenerator;
 use OCP\IUser;
 use OCP\IUserSession;
 use OCP\L10N\IFactory;
+use OCP\Notification\AlreadyProcessedException;
 use OCP\Notification\IManager;
 use OCP\Notification\INotification;
 use OCP\Notification\INotifier;
@@ -79,14 +80,35 @@ class Notifier implements INotifier {
                $this->appVersions = $this->getAppVersions();
        }
 
+       /**
+        * Identifier of the notifier, only use [a-z0-9_]
+        *
+        * @return string
+        * @since 17.0.0
+        */
+       public function getID(): string {
+               return 'updatenotification';
+       }
+
+       /**
+        * Human readable name describing the notifier
+        *
+        * @return string
+        * @since 17.0.0
+        */
+       public function getName(): string {
+               return $this->l10NFactory->get('updatenotification')->t('Update notifications');
+       }
+
        /**
         * @param INotification $notification
         * @param string $languageCode The code of the language that should be used to prepare the notification
         * @return INotification
         * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+        * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
         * @since 9.0.0
         */
-       public function prepare(INotification $notification, $languageCode): INotification {
+       public function prepare(INotification $notification, string $languageCode): INotification {
                if ($notification->getApp() !== 'updatenotification') {
                        throw new \InvalidArgumentException('Unknown app id');
                }
@@ -142,12 +164,11 @@ class Notifier implements INotifier {
         *
         * @param INotification $notification
         * @param string $installedVersion
-        * @throws \InvalidArgumentException When the update is already installed
+        * @throws AlreadyProcessedException When the update is already installed
         */
        protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) {
                if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
-                       $this->notificationManager->markProcessed($notification);
-                       throw new \InvalidArgumentException('Update already installed');
+                       throw new AlreadyProcessedException();
                }
        }
 
index 5afd928301a969998a1ce37e1574ce1736f28421..34b850e655d6b5df4705cc73024be1dfdd555efb 100644 (file)
@@ -42,17 +42,7 @@ if(count($configPrefixes) > 0) {
        $ldapWrapper = new OCA\User_LDAP\LDAP();
        $ocConfig = \OC::$server->getConfig();
        $notificationManager = \OC::$server->getNotificationManager();
-       $notificationManager->registerNotifier(function() {
-               return new \OCA\User_LDAP\Notification\Notifier(
-                       \OC::$server->getL10NFactory()
-               );
-       }, function() {
-               $l = \OC::$server->getL10N('user_ldap');
-               return [
-                       'id' => 'user_ldap',
-                       'name' => $l->t('LDAP user and group backend'),
-               ];
-       });
+       $notificationManager->registerNotifier(\OCA\User_LDAP\Notification\Notifier::class);
        $userSession = \OC::$server->getUserSession();
 
        $userPluginManager = \OC::$server->query('LDAPUserPluginManager');
index 34625a3bef42bb1e154f0b7b22d3e70aa81b95f5..2c89743fa72dbac0621d4174ee1e986d9a0ceb7b 100644 (file)
@@ -42,13 +42,33 @@ class Notifier implements INotifier {
                $this->l10nFactory = $l10nFactory;
        }
 
+       /**
+        * Identifier of the notifier, only use [a-z0-9_]
+        *
+        * @return string
+        * @since 17.0.0
+        */
+       public function getID(): string {
+               return 'user_ldap';
+       }
+
+       /**
+        * Human readable name describing the notifier
+        *
+        * @return string
+        * @since 17.0.0
+        */
+       public function getName(): string {
+               return $this->l10nFactory->get('user_ldap')->t('LDAP User backend');
+       }
+
        /**
         * @param INotification $notification
         * @param string $languageCode The code of the language that should be used to prepare the notification
         * @return INotification
         * @throws \InvalidArgumentException When the notification was not prepared by a notifier
         */
-       public function prepare(INotification $notification, $languageCode) {
+       public function prepare(INotification $notification, string $languageCode): INotification {
                if ($notification->getApp() !== 'user_ldap') {
                        // Not my app => throw
                        throw new \InvalidArgumentException();