Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Notifier::prepare() threw \InvalidArgumentException which is dep… #6806

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

namespace OCA\Text\Notification;

use InvalidArgumentException;
use OC\User\NoUserException;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\Notification\UnknownNotificationException;

class Notifier implements INotifier {
public const TYPE_MENTIONED = 'mentioned';
Expand Down Expand Up @@ -45,7 +46,7 @@ public function getName(): string {

public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== 'text') {
throw new InvalidArgumentException('Application should be text instead of ' . $notification->getApp());
throw new UnknownNotificationException('Application should be text instead of ' . $notification->getApp());
}

$l = $this->factory->get('text', $languageCode);
Expand All @@ -59,18 +60,18 @@ public function prepare(INotification $notification, string $languageCode): INot
$fileId = (int)$notification->getObjectId();

if ($sourceUserDisplayName === null) {
throw new InvalidArgumentException();
throw new UnknownNotificationException();
}

try {
$userFolder = $this->rootFolder->getUserFolder($targetUser);
} catch (NotPermittedException|NoUserException $e) {
throw new InvalidArgumentException();
throw new UnknownNotificationException();
}
$node = $userFolder->getFirstNodeById($fileId);

if ($node === null) {
throw new InvalidArgumentException();
throw new AlreadyProcessedException();
}

$fileLink = $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $node->getId()]);
Expand All @@ -91,7 +92,7 @@ public function prepare(INotification $notification, string $languageCode): INot
]);
break;
default:
throw new InvalidArgumentException();
throw new UnknownNotificationException();
}
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('text', 'app-dark.svg')));
$notification->setLink($fileLink);
Expand Down
Loading