Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,8 @@ protected function registerScripts() {
}

protected function registerNotificationNotifier() {
$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() {
return $this->getContainer()->query(Notifier::class);
}, function() {
$l = $this->getContainer()->query(IL10N::class);
return [
'id' => 'firstrunwizard',
'name' => $l->t('First run wizard'),
];
});
$this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);

/** @var AppHint $appHint */
$appHint = $this->getContainer()->query(AppHint::class);
$appHint->registerAppListener();
Expand Down
22 changes: 21 additions & 1 deletion lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,34 @@ public function __construct(IFactory $factory, IUserManager $userManager, INotif
$this->url = $urlGenerator;
}

/**
* Identifier of the notifier, only use [a-z0-9_]
*
* @return string
* @since 17.0.0
*/
public function getID(): string {
return 'firstrunwizard';
}

/**
* Human readable name describing the notifier
*
* @return string
* @since 17.0.0
*/
public function getName(): string {
return $this->factory->get('firstrunwizard')->t('First run wizard');
}

/**
* @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
* @since 9.0.0
*/
public function prepare(INotification $notification, $languageCode) {
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== 'firstrunwizard') {
// Not my app => throw
throw new \InvalidArgumentException();
Expand Down
12 changes: 2 additions & 10 deletions tests/AppInfo/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,8 @@ public function testRegisterNotifier() {

$manager = $this->createMock(IManager::class);
$manager->expects($this->once())
->method('registerNotifier')
->willReturnCallback(function($service, $info) {
$this->assertInstanceOf(\Closure::class, $service);
$this->assertInstanceOf(INotifier::class, $service());

$this->assertInstanceOf(\Closure::class, $info);
$data = $info();
$this->assertArrayHasKey('id', $data);
$this->assertArrayHasKey('name', $data);
});
->method('registerNotifierService')
->with(Notifier::class);

$this->overwriteService('NotificationManager', $manager);
$this->invokePrivate($app, 'registerNotificationNotifier');
Expand Down