Skip to content

Commit

Permalink
enh: pass params in subject
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Aug 9, 2023
1 parent 38e4ba2 commit 86db2d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 8 additions & 13 deletions apps/files_reminders/lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@

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;
Expand All @@ -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 {
Expand All @@ -67,18 +65,15 @@ public function prepare(INotification $notification, string $languageCode): INot

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/...
Expand Down
4 changes: 3 additions & 1 deletion apps/files_reminders/lib/Service/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ public function send(Reminder $reminder): void {
->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 {
Expand Down

0 comments on commit 86db2d7

Please sign in to comment.