diff options
-rw-r--r-- | lib/Notification/Notifier.php | 48 | ||||
-rw-r--r-- | tests/php/Notification/NotifierTest.php | 5 |
2 files changed, 51 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 */ diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php index 058de1905..f9f7e8fe7 100644 --- a/tests/php/Notification/NotifierTest.php +++ b/tests/php/Notification/NotifierTest.php @@ -37,6 +37,7 @@ use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\IComment; +use OCP\IDBConnection; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; @@ -53,6 +54,8 @@ use Test\TestCase; class NotifierTest extends TestCase { /** @var IFactory|MockObject */ protected $lFactory; + /** @var IFactory|MockObject */ + protected $db; /** @var IURLGenerator|MockObject */ protected $url; /** @var Config|MockObject */ @@ -87,6 +90,7 @@ class NotifierTest extends TestCase { parent::setUp(); $this->lFactory = $this->createMock(IFactory::class); + $this->db = $this->createMock(IDBConnection::class); $this->url = $this->createMock(IURLGenerator::class); $this->config = $this->createMock(Config::class); $this->userManager = $this->createMock(IUserManager::class); @@ -104,6 +108,7 @@ class NotifierTest extends TestCase { $this->notifier = new Notifier( $this->lFactory, + $this->db, $this->url, $this->config, $this->userManager, |