Notifier.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Authentication\Notifications;
  8. use OCP\L10N\IFactory as IL10nFactory;
  9. use OCP\Notification\INotification;
  10. use OCP\Notification\INotifier;
  11. use OCP\Notification\UnknownNotificationException;
  12. class Notifier implements INotifier {
  13. /** @var IL10nFactory */
  14. private $factory;
  15. public function __construct(IL10nFactory $l10nFactory) {
  16. $this->factory = $l10nFactory;
  17. }
  18. /**
  19. * @inheritDoc
  20. */
  21. public function prepare(INotification $notification, string $languageCode): INotification {
  22. if ($notification->getApp() !== 'auth') {
  23. // Not my app => throw
  24. throw new UnknownNotificationException();
  25. }
  26. // Read the language from the notification
  27. $l = $this->factory->get('lib', $languageCode);
  28. switch ($notification->getSubject()) {
  29. case 'remote_wipe_start':
  30. $notification->setParsedSubject(
  31. $l->t('Remote wipe started')
  32. )->setParsedMessage(
  33. $l->t('A remote wipe was started on device %s', $notification->getSubjectParameters())
  34. );
  35. return $notification;
  36. case 'remote_wipe_finish':
  37. $notification->setParsedSubject(
  38. $l->t('Remote wipe finished')
  39. )->setParsedMessage(
  40. $l->t('The remote wipe on %s has finished', $notification->getSubjectParameters())
  41. );
  42. return $notification;
  43. default:
  44. // Unknown subject => Unknown notification => throw
  45. throw new UnknownNotificationException();
  46. }
  47. }
  48. /**
  49. * Identifier of the notifier, only use [a-z0-9_]
  50. *
  51. * @return string
  52. * @since 17.0.0
  53. */
  54. public function getID(): string {
  55. return 'auth';
  56. }
  57. /**
  58. * Human readable name describing the notifier
  59. *
  60. * @return string
  61. * @since 17.0.0
  62. */
  63. public function getName(): string {
  64. return $this->factory->get('lib')->t('Authentication');
  65. }
  66. }