From 917cac543637016743f5375ce54c5240b0263130 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Dec 2016 15:32:39 +0100 Subject: [PATCH 1/4] Use the settings icon for the update notification Signed-off-by: Joas Schilling --- apps/updatenotification/appinfo/app.php | 5 +---- apps/updatenotification/img/notification.svg | 1 + apps/updatenotification/lib/Notification/Notifier.php | 10 +++++++++- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 apps/updatenotification/img/notification.svg diff --git a/apps/updatenotification/appinfo/app.php b/apps/updatenotification/appinfo/app.php index f5bcf34566..e3010d418b 100644 --- a/apps/updatenotification/appinfo/app.php +++ b/apps/updatenotification/appinfo/app.php @@ -43,10 +43,7 @@ if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) { $manager = \OC::$server->getNotificationManager(); $manager->registerNotifier(function() use ($manager) { - return new \OCA\UpdateNotification\Notification\Notifier( - $manager, - \OC::$server->getL10NFactory() - ); + return \OC::$server->query(\OCA\UpdateNotification\Notification\Notifier::class); }, function() { $l = \OC::$server->getL10N('updatenotification'); return [ diff --git a/apps/updatenotification/img/notification.svg b/apps/updatenotification/img/notification.svg new file mode 100644 index 0000000000..7a3f6270cb --- /dev/null +++ b/apps/updatenotification/img/notification.svg @@ -0,0 +1 @@ + diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index 3e1bc94425..ccc2c2b6e2 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -24,6 +24,7 @@ namespace OCA\UpdateNotification\Notification; +use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Notification\IManager; use OCP\Notification\INotification; @@ -31,6 +32,9 @@ use OCP\Notification\INotifier; class Notifier implements INotifier { + /** @var IURLGenerator */ + protected $url; + /** @var IManager */ protected $notificationManager; @@ -43,10 +47,12 @@ class Notifier implements INotifier { /** * Notifier constructor. * + * @param IURLGenerator $url * @param IManager $notificationManager * @param IFactory $l10NFactory */ - public function __construct(IManager $notificationManager, IFactory $l10NFactory) { + public function __construct(IURLGenerator $url, IManager $notificationManager, IFactory $l10NFactory) { + $this->url = $url; $this->notificationManager = $notificationManager; $this->l10NFactory = $l10NFactory; $this->appVersions = $this->getAppVersions(); @@ -81,6 +87,8 @@ class Notifier implements INotifier { $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])); } + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); + return $notification; } From 1aefbed55fab34c4d20b332b6d2ee3d703c6aada Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Dec 2016 15:33:13 +0100 Subject: [PATCH 2/4] Highlight the app name in the notification Signed-off-by: Joas Schilling --- .../lib/Notification/Notifier.php | 9 ++++++++- lib/public/RichObjectStrings/Definitions.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index ccc2c2b6e2..00cc94095c 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -84,7 +84,14 @@ class Notifier implements INotifier { $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); } - $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])); + $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) + ->setRichSubject($l->t('Update for {app} to version %s is available.', $notification->getObjectId()), [ + 'app' => [ + 'type' => 'app', + 'id' => $notification->getObjectType(), + 'name' => $appName, + ] + ]); } $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); diff --git a/lib/public/RichObjectStrings/Definitions.php b/lib/public/RichObjectStrings/Definitions.php index 2b35f9ceed..5f813f089f 100644 --- a/lib/public/RichObjectStrings/Definitions.php +++ b/lib/public/RichObjectStrings/Definitions.php @@ -96,6 +96,24 @@ class Definitions { ], ], ], + 'app' => [ + 'author' => 'Nextcloud', + 'app' => 'updatenotification', + 'since' => '11.0.0', + 'parameters' => [ + 'id' => [ + 'since' => '11.0.0', + 'required' => true, 'description' => 'The app id', + 'example' => 'updatenotification', + ], + 'name' => [ + 'since' => '11.0.0', + 'required' => true, + 'description' => 'The name of the app which should be used in the visual representation', + 'example' => 'Update notification', + ], + ], + ], 'calendar' => [ 'author' => 'Nextcloud', 'app' => 'dav', From 01f4c7550538a30311597d4eb9b889fbb04c4d67 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Dec 2016 15:35:49 +0100 Subject: [PATCH 3/4] Update versions to 11.0.0 Signed-off-by: Joas Schilling --- lib/public/RichObjectStrings/Definitions.php | 78 ++++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/public/RichObjectStrings/Definitions.php b/lib/public/RichObjectStrings/Definitions.php index 5f813f089f..fbde439c47 100644 --- a/lib/public/RichObjectStrings/Definitions.php +++ b/lib/public/RichObjectStrings/Definitions.php @@ -37,16 +37,16 @@ class Definitions { 'addressbook' => [ 'author' => 'Nextcloud', 'app' => 'dav', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the addressbook on the instance', 'example' => '42', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of the addressbook which should be used in the visual representation', 'example' => 'Contacts', @@ -56,16 +56,16 @@ class Definitions { 'addressbook-contact' => [ 'author' => 'Nextcloud', 'app' => 'dav', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the contact on the instance', 'example' => '42', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of the contact which should be used in the visual representation', 'example' => 'John Doe', @@ -75,21 +75,21 @@ class Definitions { 'announcement' => [ 'author' => 'Joas Schilling', 'app' => 'announcementcenter', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the announcement on the instance', 'example' => '42', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The announcement subject which should be used in the visual representation', 'example' => 'file.txt', ], 'link' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => false, 'description' => 'The full URL to the file', 'example' => 'http://localhost/index.php/apps/announcements/#23', @@ -117,16 +117,16 @@ class Definitions { 'calendar' => [ 'author' => 'Nextcloud', 'app' => 'dav', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the calendar on the instance', 'example' => '42', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of the calendar which should be used in the visual representation', 'example' => 'Personal', @@ -136,16 +136,16 @@ class Definitions { 'calendar-event' => [ 'author' => 'Nextcloud', 'app' => 'dav', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the event on the instance', 'example' => '42', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of the event which should be used in the visual representation', 'example' => 'Workout', @@ -155,16 +155,16 @@ class Definitions { 'email' => [ 'author' => 'Nextcloud', 'app' => 'sharebymail', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The mail-address used to identify the event on the instance', 'example' => 'test@localhost', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of a matching contact or the email (fallback) which should be used in the visual representation', 'example' => 'Foo Bar', @@ -174,28 +174,28 @@ class Definitions { 'file' => [ 'author' => 'Nextcloud', 'app' => 'dav', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the file on the instance', 'example' => '42', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The file name which should be used in the visual representation', 'example' => 'file.txt', ], 'path' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The full path of the file for the user', 'example' => 'path/to/file.txt', ], 'link' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => false, 'description' => 'The full URL to the file', 'example' => 'http://localhost/index.php/f/42', @@ -205,16 +205,16 @@ class Definitions { 'pending-federated-share' => [ 'author' => 'Nextcloud', 'app' => 'dav', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the federated share on the instance', 'example' => '42', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The name of the shared item which should be used in the visual representation', 'example' => 'file.txt', @@ -224,28 +224,28 @@ class Definitions { 'systemtag' => [ 'author' => 'Nextcloud', 'app' => 'core', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the systemtag on the instance', 'example' => '23', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of the systemtag which should be used in the visual representation', 'example' => 'Project 1', ], 'visibility' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'If the user can see the systemtag', 'example' => '1', ], 'assignable' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'If the user can assign the systemtag', 'example' => '0', @@ -255,22 +255,22 @@ class Definitions { 'user' => [ 'author' => 'Nextcloud', 'app' => 'core', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the user on the instance', 'example' => 'johndoe', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of the user which should be used in the visual representation', 'example' => 'John Doe', ], 'server' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => false, 'description' => 'The URL of the instance the user lives on', 'example' => 'localhost', @@ -280,16 +280,16 @@ class Definitions { 'user-group' => [ 'author' => 'Nextcloud', 'app' => 'core', - 'since' => '9.2.0', + 'since' => '11.0.0', 'parameters' => [ 'id' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The id used to identify the group on the instance', 'example' => 'supportteam', ], 'name' => [ - 'since' => '9.2.0', + 'since' => '11.0.0', 'required' => true, 'description' => 'The display name of the group which should be used in the visual representation', 'example' => 'Support Team', From 5ba13dd0e41d37c4087c1d0c02fc758983e97e31 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 2 Dec 2016 09:37:08 +0100 Subject: [PATCH 4/4] Fix tests Signed-off-by: Joas Schilling --- .../tests/Notification/NotifierTest.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php index e5ccb291b5..421fcada68 100644 --- a/apps/updatenotification/tests/Notification/NotifierTest.php +++ b/apps/updatenotification/tests/Notification/NotifierTest.php @@ -24,12 +24,16 @@ namespace OCA\UpdateNotification\Tests\Notification; use OCA\UpdateNotification\Notification\Notifier; +use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Notification\IManager; +use OCP\Notification\INotification; use Test\TestCase; class NotifierTest extends TestCase { + /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ + protected $urlGenerator; /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ protected $notificationManager; /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ @@ -38,8 +42,9 @@ class NotifierTest extends TestCase { public function setUp() { parent::setUp(); - $this->notificationManager = $this->getMockBuilder('OCP\Notification\IManager')->getMock(); - $this->l10nFactory = $this->getMockBuilder('OCP\L10n\IFactory')->getMock(); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->notificationManager = $this->createMock(IManager::class); + $this->l10nFactory = $this->createMock(IFactory::class); } /** @@ -49,12 +54,14 @@ class NotifierTest extends TestCase { protected function getNotifier(array $methods = []) { if (empty($methods)) { return new Notifier( + $this->urlGenerator, $this->notificationManager, $this->l10nFactory ); } { - return $this->getMockBuilder('OCA\UpdateNotification\Notification\Notifier') + return $this->getMockBuilder(Notifier::class) ->setConstructorArgs([ + $this->urlGenerator, $this->notificationManager, $this->l10nFactory, ]) @@ -81,7 +88,7 @@ class NotifierTest extends TestCase { public function testUpdateAlreadyInstalledCheck($versionNotification, $versionInstalled, $exception) { $notifier = $this->getNotifier(); - $notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock(); + $notification = $this->createMock(INotification::class); $notification->expects($this->once()) ->method('getObjectId') ->willReturn($versionNotification);