summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2023-01-17 15:24:18 -0300
committerVitor Mattos <vitor@php.rio>2023-01-17 15:24:18 -0300
commit4cc5f43b563118da0f7eed0b7f43e36760f2b149 (patch)
tree3102a2d139f19a4bc9b855358c287edb7753fa42 /lib
parent13eff2db46dc4312811795750ca2393a63d49cb0 (diff)
Move dismiss stored notification to specific endpoint
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/RecordingController.php17
-rw-r--r--lib/Notification/Notifier.php34
-rw-r--r--lib/Service/RecordingService.php13
3 files changed, 35 insertions, 29 deletions
diff --git a/lib/Controller/RecordingController.php b/lib/Controller/RecordingController.php
index 0948fe538..73ba4541f 100644
--- a/lib/Controller/RecordingController.php
+++ b/lib/Controller/RecordingController.php
@@ -100,4 +100,21 @@ class RecordingController extends AEnvironmentAwareController {
}
return new DataResponse();
}
+
+ /**
+ * @PublicPage
+ * @RequireModeratorParticipant
+ */
+ public function notificationDismiss(string $token, string $dateTime): DataResponse {
+ try {
+ $this->recordingService->notificationDismiss(
+ $token,
+ $this->participant->getAttendee()->getActorId(),
+ $dateTime
+ );
+ } catch (InvalidArgumentException $e) {
+ return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
+ }
+ return new DataResponse();
+ }
}
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 0ba311a19..be6b53fc8 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -41,9 +41,7 @@ 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;
@@ -61,7 +59,6 @@ use OCP\Share\IShare;
class Notifier implements INotifier {
protected IFactory $lFactory;
- private IDBConnection $db;
protected IURLGenerator $url;
protected Config $config;
protected IUserManager $userManager;
@@ -83,7 +80,6 @@ class Notifier implements INotifier {
protected array $participants = [];
public function __construct(IFactory $lFactory,
- IDBConnection $db,
IURLGenerator $url,
Config $config,
IUserManager $userManager,
@@ -99,7 +95,6 @@ class Notifier implements INotifier {
Definitions $definitions,
AddressHandler $addressHandler) {
$this->lFactory = $lFactory;
- $this->db = $db;
$this->url = $url;
$this->config = $config;
$this->userManager = $userManager;
@@ -304,6 +299,7 @@ class Notifier implements INotifier {
Participant $participant,
IL10N $l
): INotification {
+ $parameters = $notification->getSubjectParameters();
$shareAction = $notification->createAction()
->setParsedLabel($l->t('Share to chat'))
->setPrimary(true)
@@ -327,10 +323,11 @@ class Notifier implements INotifier {
->setParsedLabel($l->t('Dismiss'))
->setLink(
$this->urlGenerator->linkToRouteAbsolute(
- 'ocs.notifications.Endpoint.deleteNotification',
+ 'ocs.spreed.Recording.notificationDismiss',
[
- 'apiVersion' => 'v2',
- 'id' => $this->getNotificationId($notification),
+ 'apiVersion' => 'v1',
+ 'token' => $room->getToken(),
+ 'dateTime' => $notification->getDateTime()->format('U'),
]
),
IAction::TYPE_DELETE
@@ -352,27 +349,6 @@ class Notifier implements INotifier {
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/lib/Service/RecordingService.php b/lib/Service/RecordingService.php
index ab013d897..fb59fc8b6 100644
--- a/lib/Service/RecordingService.php
+++ b/lib/Service/RecordingService.php
@@ -29,6 +29,7 @@ use InvalidArgumentException;
use OC\User\NoUserException;
use OCA\Talk\Config;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
+use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -52,6 +53,7 @@ class RecordingService {
private ParticipantService $participantService,
private IRootFolder $rootFolder,
private IManager $notificationManager,
+ private Manager $roomManager,
private ITimeFactory $timeFactory,
private Config $config,
private RoomService $roomService
@@ -172,4 +174,15 @@ class RecordingService {
]);
$this->notificationManager->notify($notification);
}
+
+ public function notificationDismiss(string $roomToken, string $userId, string $dateTime): void {
+ $room = $this->roomManager->getRoomByToken($roomToken);
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('spreed')
+ ->setObject('chat', (string) $room->getToken())
+ ->setSubject('record_file_stored')
+ ->setDateTime($this->timeFactory->getDateTime('@' . $dateTime))
+ ->setUser($userId);
+ $this->notificationManager->markProcessed($notification);
+ }
}