diff options
author | Vitor Mattos <vitor@php.rio> | 2023-01-16 21:15:00 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2023-01-16 21:32:29 -0300 |
commit | 2895a929af1f8ab463249a914f1720d69a2ab0ae (patch) | |
tree | 0dbf8b4249e2723c95052a901fd00b81686d1090 /lib/Notification/Notifier.php | |
parent | ebd5340e895ae41bf8f4c7f9be15392cebe997c5 (diff) |
Add dismiss recording notification
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'lib/Notification/Notifier.php')
-rw-r--r-- | lib/Notification/Notifier.php | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 674413147..b99db6f8b 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -41,7 +41,9 @@ use OCA\Talk\Webinary; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\HintException; +use OCP\IDBConnection; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; @@ -59,6 +61,7 @@ use OCP\Share\IShare; class Notifier implements INotifier { protected IFactory $lFactory; + private IDBConnection $db; protected IURLGenerator $url; protected Config $config; protected IUserManager $userManager; @@ -80,6 +83,7 @@ class Notifier implements INotifier { protected array $participants = []; public function __construct(IFactory $lFactory, + IDBConnection $db, IURLGenerator $url, Config $config, IUserManager $userManager, @@ -95,6 +99,7 @@ class Notifier implements INotifier { Definitions $definitions, AddressHandler $addressHandler) { $this->lFactory = $lFactory; + $this->db = $db; $this->url = $url; $this->config = $config; $this->userManager = $userManager; @@ -293,7 +298,12 @@ class Notifier implements INotifier { return $temp; } - private function parseStoredRecording(INotification $notification, Room $room, Participant $participant, IL10N $l): INotification { + private function parseStoredRecording( + INotification $notification, + Room $room, + Participant $participant, + IL10N $l + ): INotification { $shareAction = $notification->createAction() ->setParsedLabel($l->t('Share to chat')) ->setPrimary(true) @@ -307,6 +317,18 @@ class Notifier implements INotifier { ), IAction::TYPE_POST ); + $dismissAction = $notification->createAction() + ->setParsedLabel($l->t('Dismiss')) + ->setLink( + $this->urlGenerator->linkToRouteAbsolute( + 'ocs.notifications.Endpoint.deleteNotification', + [ + 'apiVersion' => 'v2', + 'id' => $this->getNotificationId($notification), + ] + ), + IAction::TYPE_DELETE + ); $notification ->setRichSubject( @@ -319,10 +341,32 @@ class Notifier implements INotifier { 'call-type' => $this->getRoomType($room), ], ]) - ->addParsedAction($shareAction); + ->addParsedAction($shareAction) + ->addParsedAction($dismissAction); return $notification; } + public function getNotificationId(INotification $notification): int { + $sql = $this->db->getQueryBuilder(); + $sql->select('notification_id') + ->from('notifications') + ->andWhere($sql->expr()->eq('app', + $sql->createNamedParameter($notification->getApp()))) + ->andWhere($sql->expr()->eq('object_id', + $sql->createNamedParameter($notification->getObjectId()))) + ->andWhere($sql->expr()->eq('object_type', + $sql->createNamedParameter($notification->getObjectType()))) + ->andWhere($sql->expr()->eq('subject', + $sql->createNamedParameter($notification->getSubject()))) + ->andWhere($sql->expr()->eq('timestamp', + $sql->createNamedParameter($notification->getDateTime()->format('U')), + IQueryBuilder::PARAM_INT)) + ->setMaxResults(1); + + $statement = $sql->executeQuery(); + return (int) $statement->fetchOne(); + } + /** * @throws HintException */ |