Provider.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\TwoFactorBackupCodes\Activity;
  8. use OCP\Activity\Exceptions\UnknownActivityException;
  9. use OCP\Activity\IEvent;
  10. use OCP\Activity\IManager;
  11. use OCP\Activity\IProvider;
  12. use OCP\IURLGenerator;
  13. use OCP\L10N\IFactory as L10nFactory;
  14. class Provider implements IProvider {
  15. /**
  16. * @param L10nFactory $l10n
  17. * @param IURLGenerator $urlGenerator
  18. * @param IManager $activityManager
  19. */
  20. public function __construct(
  21. private L10nFactory $l10n,
  22. private IURLGenerator $urlGenerator,
  23. private IManager $activityManager,
  24. ) {
  25. }
  26. public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
  27. if ($event->getApp() !== 'twofactor_backupcodes') {
  28. throw new UnknownActivityException();
  29. }
  30. $l = $this->l10n->get('twofactor_backupcodes', $language);
  31. switch ($event->getSubject()) {
  32. case 'codes_generated':
  33. $event->setParsedSubject($l->t('You created two-factor backup codes for your account'));
  34. if ($this->activityManager->getRequirePNG()) {
  35. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
  36. } else {
  37. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
  38. }
  39. break;
  40. default:
  41. throw new UnknownActivityException();
  42. }
  43. return $event;
  44. }
  45. }