factory->get(Application::APP_ID)->t('Guests'); } private function getRichMessageParams(string $source, string $target): array { $sourceUser = $this->userManager->get($source); $targetUser = $this->userManager->get($target); return [ 'guest' => [ 'type' => $sourceUser ? 'guest' : 'highlight', 'id' => $sourceUser?->getUID() ?? $source, 'name' => $sourceUser?->getDisplayName() ?? $source, ], 'user' => [ 'type' => $targetUser ? 'user' : 'highlight', 'id' => $targetUser?->getUID() ?? $source, 'name' => $targetUser?->getDisplayName() ?? $target, ], ]; } /** * @throws UnknownNotificationException */ public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== Application::APP_ID) { // Not my app => throw throw new UnknownNotificationException(); } // Read the language from the notification $l = $this->factory->get(Application::APP_ID, $languageCode); switch ($notification->getSubject()) { case 'data_migrated_to_system_user': $notification->setParsedSubject( $l->t('Data imported') )->setParsedMessage( $l->t('Data from your previous guest account was successfully imported into your new account.') ); $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/info.svg'))); return $notification; case 'guest-transfer-fail': $params = $notification->getSubjectParameters(); $notification ->setRichSubject($l->t('Guest conversion failed')) ->setRichMessage( $l->t('Failed to convert guest {guest} account to {user} account'), $this->getRichMessageParams($params['source'], $params['target']), ); return $notification; case 'guest-transfer-done': $params = $notification->getSubjectParameters(); $notification ->setRichSubject($l->t('Guest conversion done')) ->setRichMessage( $l->t('Conversion of guest {guest} to {user} completed'), $this->getRichMessageParams($params['source'], $params['target']), ); return $notification; default: // Unknown subject => Unknown notification => throw throw new UnknownNotificationException(); } } }