Merge pull request #2437 from nextcloud/update-notification-icons

Use an icon for the update notifications
This commit is contained in:
Morris Jobke 2016-12-02 20:05:50 +01:00 committed by GitHub
commit 2bc931dd10
5 changed files with 87 additions and 49 deletions

View File

@ -43,10 +43,7 @@ if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) {
$manager = \OC::$server->getNotificationManager(); $manager = \OC::$server->getNotificationManager();
$manager->registerNotifier(function() use ($manager) { $manager->registerNotifier(function() use ($manager) {
return new \OCA\UpdateNotification\Notification\Notifier( return \OC::$server->query(\OCA\UpdateNotification\Notification\Notifier::class);
$manager,
\OC::$server->getL10NFactory()
);
}, function() { }, function() {
$l = \OC::$server->getL10N('updatenotification'); $l = \OC::$server->getL10N('updatenotification');
return [ return [

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewbox="0 0 16 16"><path d="M6.938 0A.43.43 0 0 0 6.5.438v1.25a5.818 5.818 0 0 0-1.53.656l-.907-.906a.436.436 0 0 0-.625 0l-1.5 1.5a.436.436 0 0 0 0 .624l.906.907c-.285.48-.514.976-.656 1.53H.938a.43.43 0 0 0-.438.438v2.125C.5 8.81.69 9 .938 9h1.25a5.82 5.82 0 0 0 .656 1.53l-.907.908a.436.436 0 0 0 0 .625l1.5 1.5c.176.176.45.176.625 0l.907-.907c.48.285.976.514 1.53.656v1.25c0 .25.19.438.437.438h2.125a.43.43 0 0 0 .438-.438v-1.25a5.82 5.82 0 0 0 1.53-.657l.907.907c.176.175.45.175.625 0l1.5-1.5a.436.436 0 0 0 0-.625l-.906-.906A5.79 5.79 0 0 0 13.812 9h1.25a.43.43 0 0 0 .438-.438V6.437A.43.43 0 0 0 15.062 6h-1.25a5.79 5.79 0 0 0-.656-1.532l.906-.906a.436.436 0 0 0 0-.625l-1.5-1.5a.436.436 0 0 0-.625 0l-.906.906a5.816 5.816 0 0 0-1.53-.656V.437A.43.43 0 0 0 9.063 0zM8 4.157a3.344 3.344 0 0 1 0 6.686 3.344 3.344 0 0 1 0-6.686z" display="block"/></svg>

After

Width:  |  Height:  |  Size: 923 B

View File

@ -24,6 +24,7 @@
namespace OCA\UpdateNotification\Notification; namespace OCA\UpdateNotification\Notification;
use OCP\IURLGenerator;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
@ -31,6 +32,9 @@ use OCP\Notification\INotifier;
class Notifier implements INotifier { class Notifier implements INotifier {
/** @var IURLGenerator */
protected $url;
/** @var IManager */ /** @var IManager */
protected $notificationManager; protected $notificationManager;
@ -43,10 +47,12 @@ class Notifier implements INotifier {
/** /**
* Notifier constructor. * Notifier constructor.
* *
* @param IURLGenerator $url
* @param IManager $notificationManager * @param IManager $notificationManager
* @param IFactory $l10NFactory * @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->notificationManager = $notificationManager;
$this->l10NFactory = $l10NFactory; $this->l10NFactory = $l10NFactory;
$this->appVersions = $this->getAppVersions(); $this->appVersions = $this->getAppVersions();
@ -78,9 +84,18 @@ class Notifier implements INotifier {
$this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); $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')));
return $notification; return $notification;
} }

View File

@ -24,12 +24,16 @@ namespace OCA\UpdateNotification\Tests\Notification;
use OCA\UpdateNotification\Notification\Notifier; use OCA\UpdateNotification\Notification\Notifier;
use OCP\IURLGenerator;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification;
use Test\TestCase; use Test\TestCase;
class NotifierTest extends TestCase { class NotifierTest extends TestCase {
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
protected $urlGenerator;
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
protected $notificationManager; protected $notificationManager;
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
@ -38,8 +42,9 @@ class NotifierTest extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->notificationManager = $this->getMockBuilder('OCP\Notification\IManager')->getMock(); $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10nFactory = $this->getMockBuilder('OCP\L10n\IFactory')->getMock(); $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 = []) { protected function getNotifier(array $methods = []) {
if (empty($methods)) { if (empty($methods)) {
return new Notifier( return new Notifier(
$this->urlGenerator,
$this->notificationManager, $this->notificationManager,
$this->l10nFactory $this->l10nFactory
); );
} { } {
return $this->getMockBuilder('OCA\UpdateNotification\Notification\Notifier') return $this->getMockBuilder(Notifier::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->urlGenerator,
$this->notificationManager, $this->notificationManager,
$this->l10nFactory, $this->l10nFactory,
]) ])
@ -81,7 +88,7 @@ class NotifierTest extends TestCase {
public function testUpdateAlreadyInstalledCheck($versionNotification, $versionInstalled, $exception) { public function testUpdateAlreadyInstalledCheck($versionNotification, $versionInstalled, $exception) {
$notifier = $this->getNotifier(); $notifier = $this->getNotifier();
$notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock(); $notification = $this->createMock(INotification::class);
$notification->expects($this->once()) $notification->expects($this->once())
->method('getObjectId') ->method('getObjectId')
->willReturn($versionNotification); ->willReturn($versionNotification);

View File

@ -37,16 +37,16 @@ class Definitions {
'addressbook' => [ 'addressbook' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'dav', 'app' => 'dav',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the addressbook on the instance', 'description' => 'The id used to identify the addressbook on the instance',
'example' => '42', 'example' => '42',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of the addressbook which should be used in the visual representation', 'description' => 'The display name of the addressbook which should be used in the visual representation',
'example' => 'Contacts', 'example' => 'Contacts',
@ -56,16 +56,16 @@ class Definitions {
'addressbook-contact' => [ 'addressbook-contact' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'dav', 'app' => 'dav',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the contact on the instance', 'description' => 'The id used to identify the contact on the instance',
'example' => '42', 'example' => '42',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of the contact which should be used in the visual representation', 'description' => 'The display name of the contact which should be used in the visual representation',
'example' => 'John Doe', 'example' => 'John Doe',
@ -75,40 +75,58 @@ class Definitions {
'announcement' => [ 'announcement' => [
'author' => 'Joas Schilling', 'author' => 'Joas Schilling',
'app' => 'announcementcenter', 'app' => 'announcementcenter',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'description' => 'The id used to identify the announcement on the instance', 'required' => true, 'description' => 'The id used to identify the announcement on the instance',
'example' => '42', 'example' => '42',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The announcement subject which should be used in the visual representation', 'description' => 'The announcement subject which should be used in the visual representation',
'example' => 'file.txt', 'example' => 'file.txt',
], ],
'link' => [ 'link' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => false, 'required' => false,
'description' => 'The full URL to the file', 'description' => 'The full URL to the file',
'example' => 'http://localhost/index.php/apps/announcements/#23', 'example' => 'http://localhost/index.php/apps/announcements/#23',
], ],
], ],
], ],
'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' => [ 'calendar' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'dav', 'app' => 'dav',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the calendar on the instance', 'description' => 'The id used to identify the calendar on the instance',
'example' => '42', 'example' => '42',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of the calendar which should be used in the visual representation', 'description' => 'The display name of the calendar which should be used in the visual representation',
'example' => 'Personal', 'example' => 'Personal',
@ -118,16 +136,16 @@ class Definitions {
'calendar-event' => [ 'calendar-event' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'dav', 'app' => 'dav',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the event on the instance', 'description' => 'The id used to identify the event on the instance',
'example' => '42', 'example' => '42',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of the event which should be used in the visual representation', 'description' => 'The display name of the event which should be used in the visual representation',
'example' => 'Workout', 'example' => 'Workout',
@ -137,16 +155,16 @@ class Definitions {
'email' => [ 'email' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'sharebymail', 'app' => 'sharebymail',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The mail-address used to identify the event on the instance', 'description' => 'The mail-address used to identify the event on the instance',
'example' => 'test@localhost', 'example' => 'test@localhost',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of a matching contact or the email (fallback) which should be used in the visual representation', 'description' => 'The display name of a matching contact or the email (fallback) which should be used in the visual representation',
'example' => 'Foo Bar', 'example' => 'Foo Bar',
@ -156,28 +174,28 @@ class Definitions {
'file' => [ 'file' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'dav', 'app' => 'dav',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the file on the instance', 'description' => 'The id used to identify the file on the instance',
'example' => '42', 'example' => '42',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The file name which should be used in the visual representation', 'description' => 'The file name which should be used in the visual representation',
'example' => 'file.txt', 'example' => 'file.txt',
], ],
'path' => [ 'path' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The full path of the file for the user', 'description' => 'The full path of the file for the user',
'example' => 'path/to/file.txt', 'example' => 'path/to/file.txt',
], ],
'link' => [ 'link' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => false, 'required' => false,
'description' => 'The full URL to the file', 'description' => 'The full URL to the file',
'example' => 'http://localhost/index.php/f/42', 'example' => 'http://localhost/index.php/f/42',
@ -187,16 +205,16 @@ class Definitions {
'pending-federated-share' => [ 'pending-federated-share' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'dav', 'app' => 'dav',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the federated share on the instance', 'description' => 'The id used to identify the federated share on the instance',
'example' => '42', 'example' => '42',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The name of the shared item which should be used in the visual representation', 'description' => 'The name of the shared item which should be used in the visual representation',
'example' => 'file.txt', 'example' => 'file.txt',
@ -206,28 +224,28 @@ class Definitions {
'systemtag' => [ 'systemtag' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'core', 'app' => 'core',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the systemtag on the instance', 'description' => 'The id used to identify the systemtag on the instance',
'example' => '23', 'example' => '23',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of the systemtag which should be used in the visual representation', 'description' => 'The display name of the systemtag which should be used in the visual representation',
'example' => 'Project 1', 'example' => 'Project 1',
], ],
'visibility' => [ 'visibility' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'If the user can see the systemtag', 'description' => 'If the user can see the systemtag',
'example' => '1', 'example' => '1',
], ],
'assignable' => [ 'assignable' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'If the user can assign the systemtag', 'description' => 'If the user can assign the systemtag',
'example' => '0', 'example' => '0',
@ -237,22 +255,22 @@ class Definitions {
'user' => [ 'user' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'core', 'app' => 'core',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the user on the instance', 'description' => 'The id used to identify the user on the instance',
'example' => 'johndoe', 'example' => 'johndoe',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of the user which should be used in the visual representation', 'description' => 'The display name of the user which should be used in the visual representation',
'example' => 'John Doe', 'example' => 'John Doe',
], ],
'server' => [ 'server' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => false, 'required' => false,
'description' => 'The URL of the instance the user lives on', 'description' => 'The URL of the instance the user lives on',
'example' => 'localhost', 'example' => 'localhost',
@ -262,16 +280,16 @@ class Definitions {
'user-group' => [ 'user-group' => [
'author' => 'Nextcloud', 'author' => 'Nextcloud',
'app' => 'core', 'app' => 'core',
'since' => '9.2.0', 'since' => '11.0.0',
'parameters' => [ 'parameters' => [
'id' => [ 'id' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The id used to identify the group on the instance', 'description' => 'The id used to identify the group on the instance',
'example' => 'supportteam', 'example' => 'supportteam',
], ],
'name' => [ 'name' => [
'since' => '9.2.0', 'since' => '11.0.0',
'required' => true, 'required' => true,
'description' => 'The display name of the group which should be used in the visual representation', 'description' => 'The display name of the group which should be used in the visual representation',
'example' => 'Support Team', 'example' => 'Support Team',