getApp() !== 'text') { throw new UnknownNotificationException('Application should be text instead of ' . $notification->getApp()); } $l = $this->factory->get('text', $languageCode); $notification->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('text', 'app-dark.svg'))); switch ($notification->getSubject()) { case self::TYPE_MENTIONED: $parameters = $notification->getSubjectParameters(); $sourceUser = $parameters[self::SUBJECT_MENTIONED_SOURCE_USER]; $sourceUserDisplayName = $this->userManager->getDisplayName($sourceUser); $targetUser = $notification->getUser(); $fileId = (int)$notification->getObjectId(); if ($sourceUserDisplayName === null) { throw new UnknownNotificationException(); } try { $userFolder = $this->rootFolder->getUserFolder($targetUser); } catch (NotPermittedException|NoUserException $e) { throw new UnknownNotificationException(); } $node = $userFolder->getFirstNodeById($fileId); if (!$node instanceof File) { throw new AlreadyProcessedException(); } $fileLink = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $node->getId()]); $notification->setLink($fileLink); $notification->setRichSubject($l->t('{user} has mentioned you in the text document {node}'), [ 'user' => [ 'type' => 'user', 'id' => $sourceUser, 'name' => $sourceUserDisplayName, ], 'node' => [ 'type' => 'file', 'id' => (string)$node->getId(), 'name' => $node->getName(), 'path' => $userFolder->getRelativePath($node->getPath()) ?? '', 'link' => $fileLink, ], ]); $this->eventDispatcher->dispatchTyped(new MentionEvent($notification, $node)); break; default: throw new UnknownNotificationException(); } $this->setParsedSubjectFromRichSubject($notification); return $notification; } protected function setParsedSubjectFromRichSubject(INotification $notification): void { $placeholders = $replacements = []; foreach ($notification->getRichSubjectParameters() as $placeholder => $parameter) { $placeholders[] = '{' . $placeholder . '}'; if ($parameter['type'] === 'file') { $replacements[] = $parameter['path']; } else { $replacements[] = $parameter['name']; } } $notification->setParsedSubject(str_replace($placeholders, $replacements, $notification->getRichSubject())); } }