Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use NC dismiss-notification instead of button to mark notification as…
… read

Signed-off-by: Artur Neumann <[email protected]>
  • Loading branch information
individual-it committed Nov 8, 2022
commit 7d0684ca0e4dd212737e111db9a101ca31972d3a
38 changes: 26 additions & 12 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
namespace OCA\OpenProject\Notification;

use InvalidArgumentException;
use OCA\OpenProject\Service\OpenProjectAPIService;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\IDismissableNotifier;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCA\OpenProject\AppInfo\Application;

class Notifier implements INotifier {
class Notifier implements INotifier, IDismissableNotifier {

/** @var IFactory */
protected $factory;
Expand All @@ -34,6 +36,11 @@ class Notifier implements INotifier {
/** @var IURLGenerator */
protected $url;

/**
* @var OpenProjectAPIService
*/
private $openprojectAPIService;

/**
* @param IFactory $factory
* @param IUserManager $userManager
Expand All @@ -43,11 +50,13 @@ class Notifier implements INotifier {
public function __construct(IFactory $factory,
IUserManager $userManager,
INotificationManager $notificationManager,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
OpenProjectAPIService $openprojectAPIService) {
$this->factory = $factory;
$this->userManager = $userManager;
$this->notificationManager = $notificationManager;
$this->url = $urlGenerator;
$this->openprojectAPIService = $openprojectAPIService;
}

/**
Expand Down Expand Up @@ -107,15 +116,6 @@ public function prepare(INotification $notification, string $languageCode): INot
$message .= $actor . ',';
}
$message = rtrim($message, ',');
$markAsReadAction = $notification->createAction();
$markAsReadAction->setLabel('mark_as_read')
->setParsedLabel($l->t('Mark as read'))
->setPrimary(true)
->setLink($this->url->linkToRouteAbsolute(
'integration_openproject.openProjectAPI.markNotificationAsRead',
['workpackageId' => $p['wpId']]),
'DELETE'
);

$notification->setParsedSubject('(' . $p['count']. ') ' . $p['resourceTitle'])
->setParsedMessage('--')
Expand All @@ -126,7 +126,6 @@ public function prepare(INotification $notification, string $languageCode): INot
'instance' => $richSubjectInstance,
]
)
->addParsedAction($markAsReadAction)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
return $notification;

Expand All @@ -135,4 +134,19 @@ public function prepare(INotification $notification, string $languageCode): INot
throw new InvalidArgumentException();
}
}


/**
* @inheritDoc
*/
public function dismissNotification(INotification $notification): void {
if ($notification->getApp() !== Application::APP_ID) {
throw new \InvalidArgumentException('Unhandled app');
}
$parameters = $notification->getSubjectParameters();
$this->openprojectAPIService->markAllNotificationsOfWorkPackageAsRead(
$parameters['wpId'],
$notification->getUser()
);
}
}