From 0c0ed382f84ad1b5f1ca1ee6165dfa79c6118f0a Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Wed, 9 Aug 2023 10:20:32 -0700 Subject: enh: pass params in subject Signed-off-by: Christopher Ng (cherry picked from commit 86db2d7f15f8507e9c563507491b7dba3c63e932) --- apps/files_reminders/lib/Notification/Notifier.php | 21 ++++++++------------- .../files_reminders/lib/Service/ReminderService.php | 4 +++- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'apps/files_reminders/lib') diff --git a/apps/files_reminders/lib/Notification/Notifier.php b/apps/files_reminders/lib/Notification/Notifier.php index c528aa521b1..ce46aafb86c 100644 --- a/apps/files_reminders/lib/Notification/Notifier.php +++ b/apps/files_reminders/lib/Notification/Notifier.php @@ -28,10 +28,8 @@ namespace OCA\FilesReminders\Notification; use InvalidArgumentException; use OCA\FilesReminders\AppInfo\Application; -use OCA\FilesReminders\Exception\NodeNotFoundException; -use OCA\FilesReminders\Service\ReminderService; -use OCP\AppFramework\Db\DoesNotExistException; use OCP\Files\FileInfo; +use OCP\Files\IRootFolder; use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Notification\AlreadyProcessedException; @@ -43,7 +41,7 @@ class Notifier implements INotifier { public function __construct( protected IFactory $l10nFactory, protected IURLGenerator $urlGenerator, - protected ReminderService $reminderService, + protected IRootFolder $root, ) {} public function getID(): string { @@ -67,18 +65,15 @@ class Notifier implements INotifier { switch ($notification->getSubject()) { case 'reminder-due': - $reminderId = (int)$notification->getObjectId(); - try { - $reminder = $this->reminderService->get($reminderId); - } catch (DoesNotExistException $e) { - throw new AlreadyProcessedException(); - } + $params = $notification->getSubjectParameters(); + $fileId = $params['fileId']; - try { - $node = $reminder->getNode(); - } catch (NodeNotFoundException $e) { + $nodes = $this->root->getUserFolder($notification->getUser())->getById($fileId); + if (empty($nodes)) { throw new InvalidArgumentException(); } + $node = reset($nodes); + $path = rtrim($node->getPath(), '/'); if (strpos($path, '/' . $notification->getUser() . '/files/') === 0) { // Remove /user/files/... diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php index 010f458e872..4bfa943cb04 100644 --- a/apps/files_reminders/lib/Service/ReminderService.php +++ b/apps/files_reminders/lib/Service/ReminderService.php @@ -155,7 +155,9 @@ class ReminderService { ->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('files', 'folder.svg'))) ->setUser($user->getUID()) ->setObject('reminder', (string)$reminder->getId()) - ->setSubject('reminder-due') + ->setSubject('reminder-due', [ + 'fileId' => $reminder->getFileId(), + ]) ->setDateTime($reminder->getDueDate()); try { -- cgit v1.2.3