* * @author Double Bastion LLC * * @license GNU AGPL version 3 or any later version * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see . * */ declare(strict_types=1); namespace OCA\PaxFax\Notification; use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Notification\INotification; use OCP\Notification\INotifier; use OCP\Notification\UnknownNotificationException; class Notifier implements INotifier { /** @var IFactory */ protected $l10nFactory; /** @var IUrlGenerator */ private $IUrlGenerator; /** * Notifier constructor. * * @param IFactory $l10nFactory * @param IUrlGenerator $IUrlGenerator */ public function __construct(IFactory $l10nFactory, IURLGenerator $IUrlGenerator) { $this->l10nFactory = $l10nFactory; $this->IUrlGenerator = $IUrlGenerator; } /** * Identifier of the notifier, only use [a-z0-9_] * * @return string * @since 17.0.0 */ public function getID(): string { return 'pax_fax'; } /** * Human readable name describing the notifier * * @return string * @since 17.0.0 */ public function getName(): string { return $this->l10nFactory->get('pax_fax')->t('New fax'); } /** * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification * @return INotification * @throws OCP\Notification\UnknownNotificationException when the notification was not prepared by a notifier */ public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== 'pax_fax') { // It's not my app, so, throw an exception throw new UnknownNotificationException(); } // Read the language from the notification $l = $this->l10nFactory->get('pax_fax', $languageCode); $iconPath = $this->IUrlGenerator->imagePath('pax_fax', 'pax_fax_dark.svg'); $notification->setIcon($this->IUrlGenerator->getAbsoluteURL($iconPath)); $notification->setParsedSubject($l->t('New fax from Pax Fax')); return $notification; } }