From 2382c9a33e7b096af633e055b7823915ab58dada Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 5 Jan 2023 14:13:28 -0300 Subject: Notify recording stored Signed-off-by: Vitor Mattos --- lib/Service/RecordingService.php | 78 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index a8d7b666f..38fbf5319 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -29,12 +29,18 @@ use InvalidArgumentException; use OC\User\NoUserException; use OCA\Talk\Config; use OCA\Talk\Exceptions\ParticipantNotFoundException; +use OCA\Talk\Participant; use OCA\Talk\Room; +use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Notification\IAction; +use OCP\Notification\IManager; class RecordingService { public const DEFAULT_ALLOWED_RECORDING_FORMATS = [ @@ -47,6 +53,9 @@ class RecordingService { private IMimeTypeDetector $mimeTypeDetector, private ParticipantService $participantService, private IRootFolder $rootFolder, + private IManager $notificationManager, + private IL10N $l, + private IURLGenerator $urlGenerator, private Config $config, private RoomService $roomService ) { @@ -80,14 +89,15 @@ class RecordingService { $this->validateFileFormat($fileName, $content); try { - $this->participantService->getParticipant($room, $owner); + $participant = $this->participantService->getParticipant($room, $owner); } catch (ParticipantNotFoundException $e) { throw new InvalidArgumentException('owner_participant'); } try { $recordingFolder = $this->getRecordingFolder($owner, $room->getToken()); - $recordingFolder->newFile($fileName, $content); + $file = $recordingFolder->newFile($fileName, $content); + $this->notifyStoredRecording($room, $participant, $file); } catch (NoUserException $e) { throw new InvalidArgumentException('owner_invalid'); } catch (NotPermittedException $e) { @@ -142,4 +152,68 @@ class RecordingService { } return $recordingFolder; } + + public function notifyStoredRecording(Room $room, Participant $participant, File $file): void { + $attendee = $participant->getAttendee(); + $notificationLevel = $attendee->getNotificationLevel(); + if ($notificationLevel === Participant::NOTIFY_NEVER) { + return; + } + + $notification = $this->notificationManager->createNotification(); + + $shareAction = $notification->createAction() + ->setParsedLabel($this->l->t('Share to chat')) + ->setPrimary(true) + ->setLink( + $this->urlGenerator->linkToRouteAbsolute( + 'spreed.Chat.shareObjectToChat', + [ + 'token' => $room->getToken() + ] + ), + IAction::TYPE_POST + ); + + $notification + ->setApp('spreed') + ->setDateTime(new \DateTime()) + ->setObject('chat', $room->getToken()) + ->setUser($attendee->getActorId()) + ->setSubject('file', [ + 'objectType' => 'file', + 'objectId' => $file->getId(), + 'actorDisplayName' => $attendee->getDisplayName(), + ]) + ->setRichSubject( + $this->l->t('Record file of {call}'), + [ + 'call' => [ + 'type' => 'call', + 'id' => $room->getId(), + 'name' => $room->getDisplayName((string) $attendee->getId()), + 'call-type' => $this->getRoomType($room), + ], + ]) + ->addParsedAction($shareAction); + $this->notificationManager->notify($notification); + } + + /** + * @param Room $room + * @return string + * @throws \InvalidArgumentException + */ + protected function getRoomType(Room $room): string { + switch ($room->getType()) { + case Room::TYPE_ONE_TO_ONE: + return 'one2one'; + case Room::TYPE_GROUP: + return 'group'; + case Room::TYPE_PUBLIC: + return 'public'; + default: + throw new \InvalidArgumentException('Unknown room type'); + } + } } -- cgit v1.2.3 From 2a12d6037a3a9a37bb216f1ae95ac0f08f3622c2 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 12 Jan 2023 10:57:36 -0300 Subject: Parse stored recording notification Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 36 ++++++++++++++++++++++++++++++++++++ lib/Service/RecordingService.php | 33 ++------------------------------- 2 files changed, 38 insertions(+), 31 deletions(-) (limited to 'lib') diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 46c6b7b77..52d08a89b 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -64,6 +64,7 @@ class Notifier implements INotifier { protected IUserManager $userManager; protected GuestManager $guestManager; private IShareManager $shareManager; + private IURLGenerator $urlGenerator; protected Manager $manager; protected ParticipantService $participantService; protected INotificationManager $notificationManager; @@ -84,6 +85,7 @@ class Notifier implements INotifier { IUserManager $userManager, GuestManager $guestManager, IShareManager $shareManager, + IURLGenerator $urlGenerator, Manager $manager, ParticipantService $participantService, INotificationManager $notificationManager, @@ -98,6 +100,7 @@ class Notifier implements INotifier { $this->userManager = $userManager; $this->guestManager = $guestManager; $this->shareManager = $shareManager; + $this->urlGenerator = $urlGenerator; $this->manager = $manager; $this->participantService = $participantService; $this->notificationManager = $notificationManager; @@ -248,6 +251,9 @@ class Notifier implements INotifier { ->setLink($this->url->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()])); $subject = $notification->getSubject(); + if ($subject === 'record_file_stored') { + return $this->parseStoredRecording($notification, $room, $participant, $l); + } if ($subject === 'invitation') { return $this->parseInvitation($notification, $room, $l); } @@ -287,6 +293,36 @@ class Notifier implements INotifier { return $temp; } + private function parseStoredRecording(INotification $notification, Room $room, Participant $participant, IL10N $l): INOtification { + $shareAction = $notification->createAction() + ->setParsedLabel($l->t('Share to chat')) + ->setPrimary(true) + ->setLink( + $this->urlGenerator->linkToRouteAbsolute( + 'ocs.spreed.Chat.shareObjectToChat', + [ + 'apiVersion' => 'v1', + 'token' => $room->getToken() + ] + ), + IAction::TYPE_POST + ); + + $notification + ->setRichSubject( + $l->t('Record file of {call}'), + [ + 'call' => [ + 'type' => 'call', + 'id' => $room->getId(), + 'name' => $room->getDisplayName((string) $participant->getAttendee()->getId()), + 'call-type' => $this->getRoomType($room), + ], + ]) + ->addParsedAction($shareAction); + return $notification; + } + /** * @throws HintException */ diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index 38fbf5319..944e3c916 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -37,9 +37,6 @@ use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; -use OCP\IL10N; -use OCP\IURLGenerator; -use OCP\Notification\IAction; use OCP\Notification\IManager; class RecordingService { @@ -54,8 +51,6 @@ class RecordingService { private ParticipantService $participantService, private IRootFolder $rootFolder, private IManager $notificationManager, - private IL10N $l, - private IURLGenerator $urlGenerator, private Config $config, private RoomService $roomService ) { @@ -162,40 +157,16 @@ class RecordingService { $notification = $this->notificationManager->createNotification(); - $shareAction = $notification->createAction() - ->setParsedLabel($this->l->t('Share to chat')) - ->setPrimary(true) - ->setLink( - $this->urlGenerator->linkToRouteAbsolute( - 'spreed.Chat.shareObjectToChat', - [ - 'token' => $room->getToken() - ] - ), - IAction::TYPE_POST - ); - $notification ->setApp('spreed') ->setDateTime(new \DateTime()) ->setObject('chat', $room->getToken()) ->setUser($attendee->getActorId()) - ->setSubject('file', [ + ->setSubject('record_file_stored', [ 'objectType' => 'file', 'objectId' => $file->getId(), 'actorDisplayName' => $attendee->getDisplayName(), - ]) - ->setRichSubject( - $this->l->t('Record file of {call}'), - [ - 'call' => [ - 'type' => 'call', - 'id' => $room->getId(), - 'name' => $room->getDisplayName((string) $attendee->getId()), - 'call-type' => $this->getRoomType($room), - ], - ]) - ->addParsedAction($shareAction); + ]); $this->notificationManager->notify($notification); } -- cgit v1.2.3 From 71aa1692c51ea845e70e74f498e201748fd10702 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 13 Jan 2023 13:44:58 -0300 Subject: Refactors after code review Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 4 ++-- lib/Service/RecordingService.php | 22 +++------------------- 2 files changed, 5 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 52d08a89b..936006a4b 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -293,7 +293,7 @@ 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) @@ -310,7 +310,7 @@ class Notifier implements INotifier { $notification ->setRichSubject( - $l->t('Record file of {call}'), + $l->t('Recording for the call in {call} was uploaded.'), [ 'call' => [ 'type' => 'call', diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index 944e3c916..a20143d9d 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -31,6 +31,7 @@ use OCA\Talk\Config; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; @@ -51,6 +52,7 @@ class RecordingService { private ParticipantService $participantService, private IRootFolder $rootFolder, private IManager $notificationManager, + private ITimeFactory $timeFactory, private Config $config, private RoomService $roomService ) { @@ -159,7 +161,7 @@ class RecordingService { $notification ->setApp('spreed') - ->setDateTime(new \DateTime()) + ->setDateTime($this->timeFactory->getDateTime()) ->setObject('chat', $room->getToken()) ->setUser($attendee->getActorId()) ->setSubject('record_file_stored', [ @@ -169,22 +171,4 @@ class RecordingService { ]); $this->notificationManager->notify($notification); } - - /** - * @param Room $room - * @return string - * @throws \InvalidArgumentException - */ - protected function getRoomType(Room $room): string { - switch ($room->getType()) { - case Room::TYPE_ONE_TO_ONE: - return 'one2one'; - case Room::TYPE_GROUP: - return 'group'; - case Room::TYPE_PUBLIC: - return 'public'; - default: - throw new \InvalidArgumentException('Unknown room type'); - } - } } -- cgit v1.2.3 From f44a9f7662dbdcb2b0dddd2a18566378e897e7e8 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 13 Jan 2023 14:56:13 -0300 Subject: Fix unit tests Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 936006a4b..a396e79fd 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -64,12 +64,12 @@ class Notifier implements INotifier { protected IUserManager $userManager; protected GuestManager $guestManager; private IShareManager $shareManager; - private IURLGenerator $urlGenerator; protected Manager $manager; protected ParticipantService $participantService; protected INotificationManager $notificationManager; protected ICommentsManager $commentManager; protected MessageParser $messageParser; + private IURLGenerator $urlGenerator; protected ITimeFactory $timeFactory; protected Definitions $definitions; protected AddressHandler $addressHandler; @@ -85,12 +85,12 @@ class Notifier implements INotifier { IUserManager $userManager, GuestManager $guestManager, IShareManager $shareManager, - IURLGenerator $urlGenerator, Manager $manager, ParticipantService $participantService, INotificationManager $notificationManager, CommentsManager $commentManager, MessageParser $messageParser, + IURLGenerator $urlGenerator, ITimeFactory $timeFactory, Definitions $definitions, AddressHandler $addressHandler) { @@ -100,12 +100,12 @@ class Notifier implements INotifier { $this->userManager = $userManager; $this->guestManager = $guestManager; $this->shareManager = $shareManager; - $this->urlGenerator = $urlGenerator; $this->manager = $manager; $this->participantService = $participantService; $this->notificationManager = $notificationManager; $this->commentManager = $commentManager; $this->messageParser = $messageParser; + $this->urlGenerator = $urlGenerator; $this->timeFactory = $timeFactory; $this->definitions = $definitions; $this->addressHandler = $addressHandler; -- cgit v1.2.3 From ebd5340e895ae41bf8f4c7f9be15392cebe997c5 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 16 Jan 2023 11:33:31 -0300 Subject: Fix room name and integration test Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index a396e79fd..674413147 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -315,7 +315,7 @@ class Notifier implements INotifier { 'call' => [ 'type' => 'call', 'id' => $room->getId(), - 'name' => $room->getDisplayName((string) $participant->getAttendee()->getId()), + 'name' => $room->getDisplayName((string) $participant->getAttendee()->getActorId()), 'call-type' => $this->getRoomType($room), ], ]) -- cgit v1.2.3 From 2895a929af1f8ab463249a914f1720d69a2ab0ae Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 16 Jan 2023 21:15:00 -0300 Subject: Add dismiss recording notification Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 48 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'lib') 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 */ -- cgit v1.2.3 From 13eff2db46dc4312811795750ca2393a63d49cb0 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 17 Jan 2023 15:17:45 -0300 Subject: Fix share file to room Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 8 +++++++- lib/Service/RecordingService.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index b99db6f8b..0ba311a19 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -312,6 +312,12 @@ class Notifier implements INotifier { 'ocs.spreed.Chat.shareObjectToChat', [ 'apiVersion' => 'v1', + 'objectType' => 'file', + 'objectId' => $notification->getObjectId(), + 'metaData' => json_encode([ + 'name' => $parameters['name'], + 'path' => $parameters['name'], + ]), 'token' => $room->getToken() ] ), @@ -337,7 +343,7 @@ class Notifier implements INotifier { 'call' => [ 'type' => 'call', 'id' => $room->getId(), - 'name' => $room->getDisplayName((string) $participant->getAttendee()->getActorId()), + 'name' => $room->getDisplayName($participant->getAttendee()->getActorId()), 'call-type' => $this->getRoomType($room), ], ]) diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index a20143d9d..ab013d897 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -167,6 +167,7 @@ class RecordingService { ->setSubject('record_file_stored', [ 'objectType' => 'file', 'objectId' => $file->getId(), + 'name' => $file->getName(), 'actorDisplayName' => $attendee->getDisplayName(), ]); $this->notificationManager->notify($notification); -- cgit v1.2.3 From 4cc5f43b563118da0f7eed0b7f43e36760f2b149 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 17 Jan 2023 15:24:18 -0300 Subject: Move dismiss stored notification to specific endpoint Signed-off-by: Vitor Mattos --- lib/Controller/RecordingController.php | 17 +++++++++++++++++ lib/Notification/Notifier.php | 34 +++++----------------------------- lib/Service/RecordingService.php | 13 +++++++++++++ 3 files changed, 35 insertions(+), 29 deletions(-) (limited to 'lib') 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); + } } -- cgit v1.2.3 From aed32de2c7423d701dda28e49478483481bd28e9 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 17 Jan 2023 15:26:07 -0300 Subject: CHange to more specific text Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index be6b53fc8..f79abbd88 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -320,7 +320,7 @@ class Notifier implements INotifier { IAction::TYPE_POST ); $dismissAction = $notification->createAction() - ->setParsedLabel($l->t('Dismiss')) + ->setParsedLabel($l->t('Dismiss notification')) ->setLink( $this->urlGenerator->linkToRouteAbsolute( 'ocs.spreed.Recording.notificationDismiss', -- cgit v1.2.3 From cb967754abd840dd353127a087d7c85c6dba7c80 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 18 Jan 2023 16:55:00 -0300 Subject: Fixes to share stored recording Signed-off-by: Vitor Mattos --- lib/Controller/RecordingController.php | 26 ++++++++-- lib/Notification/Notifier.php | 32 +++++++----- lib/Service/RecordingService.php | 92 ++++++++++++++++++++++++++++------ 3 files changed, 119 insertions(+), 31 deletions(-) (limited to 'lib') diff --git a/lib/Controller/RecordingController.php b/lib/Controller/RecordingController.php index 73ba4541f..a1670c618 100644 --- a/lib/Controller/RecordingController.php +++ b/lib/Controller/RecordingController.php @@ -105,12 +105,30 @@ class RecordingController extends AEnvironmentAwareController { * @PublicPage * @RequireModeratorParticipant */ - public function notificationDismiss(string $token, string $dateTime): DataResponse { + public function notificationDismiss(int $timestamp): DataResponse { try { $this->recordingService->notificationDismiss( - $token, - $this->participant->getAttendee()->getActorId(), - $dateTime + $this->getRoom(), + $this->participant, + $timestamp + ); + } catch (InvalidArgumentException $e) { + return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); + } + return new DataResponse(); + } + + /** + * @PublicPage + * @RequireModeratorParticipant + */ + public function shareToChat(int $fileId, int $timestamp): DataResponse { + try { + $this->recordingService->shareToChat( + $this->getRoom(), + $this->participant, + $fileId, + $timestamp ); } catch (InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index f79abbd88..b9e65147e 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -41,6 +41,7 @@ use OCA\Talk\Webinary; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; +use OCP\Files\IRootFolder; use OCP\HintException; use OCP\IL10N; use OCP\IURLGenerator; @@ -69,7 +70,8 @@ class Notifier implements INotifier { protected INotificationManager $notificationManager; protected ICommentsManager $commentManager; protected MessageParser $messageParser; - private IURLGenerator $urlGenerator; + protected IURLGenerator $urlGenerator; + protected IRootFolder $rootFolder; protected ITimeFactory $timeFactory; protected Definitions $definitions; protected AddressHandler $addressHandler; @@ -91,6 +93,7 @@ class Notifier implements INotifier { CommentsManager $commentManager, MessageParser $messageParser, IURLGenerator $urlGenerator, + IRootFolder $rootFolder, ITimeFactory $timeFactory, Definitions $definitions, AddressHandler $addressHandler) { @@ -106,6 +109,7 @@ class Notifier implements INotifier { $this->commentManager = $commentManager; $this->messageParser = $messageParser; $this->urlGenerator = $urlGenerator; + $this->rootFolder = $rootFolder; $this->timeFactory = $timeFactory; $this->definitions = $definitions; $this->addressHandler = $addressHandler; @@ -300,20 +304,24 @@ class Notifier implements INotifier { IL10N $l ): INotification { $parameters = $notification->getSubjectParameters(); + try { + $userFolder = $this->rootFolder->getUserFolder($notification->getUser()); + /** @var \OCP\Files\File[] */ + $files = $userFolder->getById($parameters['objectId']); + $file = array_shift($files); + } catch (\Throwable $th) { + throw new AlreadyProcessedException(); + } $shareAction = $notification->createAction() ->setParsedLabel($l->t('Share to chat')) ->setPrimary(true) ->setLink( - $this->urlGenerator->linkToRouteAbsolute( - 'ocs.spreed.Chat.shareObjectToChat', + $this->urlGenerator->linkToOCSRouteAbsolute( + 'spreed.Recording.shareToChat', [ 'apiVersion' => 'v1', - 'objectType' => 'file', - 'objectId' => $notification->getObjectId(), - 'metaData' => json_encode([ - 'name' => $parameters['name'], - 'path' => $parameters['name'], - ]), + 'fileId' => $file->getId(), + 'timestamp' => $notification->getDateTime()->getTimestamp(), 'token' => $room->getToken() ] ), @@ -322,12 +330,12 @@ class Notifier implements INotifier { $dismissAction = $notification->createAction() ->setParsedLabel($l->t('Dismiss notification')) ->setLink( - $this->urlGenerator->linkToRouteAbsolute( - 'ocs.spreed.Recording.notificationDismiss', + $this->urlGenerator->linkToOCSRouteAbsolute( + 'spreed.Recording.notificationDismiss', [ 'apiVersion' => 'v1', 'token' => $room->getToken(), - 'dateTime' => $notification->getDateTime()->format('U'), + 'timestamp' => $notification->getDateTime()->getTimestamp(), ] ), IAction::TYPE_DELETE diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index fb59fc8b6..e74508cc3 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -27,12 +27,14 @@ namespace OCA\Talk\Service; use InvalidArgumentException; use OC\User\NoUserException; +use OCA\Talk\Chat\ChatManager; 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; +use OCP\Comments\MessageTooLongException; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; @@ -40,6 +42,8 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Notification\IManager; +use OCP\Share\IManager as ShareManager; +use OCP\Share\IShare; class RecordingService { public const DEFAULT_ALLOWED_RECORDING_FORMATS = [ @@ -49,14 +53,16 @@ class RecordingService { ]; public function __construct( - private IMimeTypeDetector $mimeTypeDetector, - private ParticipantService $participantService, - private IRootFolder $rootFolder, - private IManager $notificationManager, - private Manager $roomManager, - private ITimeFactory $timeFactory, - private Config $config, - private RoomService $roomService + protected IMimeTypeDetector $mimeTypeDetector, + protected ParticipantService $participantService, + protected IRootFolder $rootFolder, + protected IManager $notificationManager, + protected Manager $roomManager, + protected ITimeFactory $timeFactory, + protected Config $config, + protected RoomService $roomService, + protected ShareManager $shareManager, + protected ChatManager $chatManager ) { } @@ -167,22 +173,78 @@ class RecordingService { ->setObject('chat', $room->getToken()) ->setUser($attendee->getActorId()) ->setSubject('record_file_stored', [ - 'objectType' => 'file', 'objectId' => $file->getId(), - 'name' => $file->getName(), - 'actorDisplayName' => $attendee->getDisplayName(), ]); $this->notificationManager->notify($notification); } - public function notificationDismiss(string $roomToken, string $userId, string $dateTime): void { - $room = $this->roomManager->getRoomByToken($roomToken); + public function notificationDismiss(Room $room, Participant $participant, int $timestamp): void { $notification = $this->notificationManager->createNotification(); $notification->setApp('spreed') ->setObject('chat', (string) $room->getToken()) ->setSubject('record_file_stored') - ->setDateTime($this->timeFactory->getDateTime('@' . $dateTime)) - ->setUser($userId); + ->setDateTime($this->timeFactory->getDateTime('@' . $timestamp)) + ->setUser($participant->getAttendee()->getActorId()); $this->notificationManager->markProcessed($notification); } + + private function getTypeOfShare(string $mimetype): string { + if (strpos($mimetype, 'video') !== false) { + return'record-video'; + } + return 'record-audio'; + } + + public function shareToChat(Room $room, Participant $participant, int $fileId, int $timestamp): void { + try { + $userFolder = $this->rootFolder->getUserFolder( + $participant->getAttendee()->getActorId() + ); + /** @var \OCP\Files\File[] */ + $files = $userFolder->getById($fileId); + $file = array_shift($files); + } catch (\Throwable $th) { + throw new InvalidArgumentException('file'); + } + + $creationDateTime = $this->timeFactory->getDateTime(); + + $share = $this->shareManager->newShare(); + $share->setNodeId($fileId) + ->setShareTime($creationDateTime) + ->setSharedBy($participant->getAttendee()->getActorId()) + ->setNode($file) + ->setShareType(IShare::TYPE_ROOM) + ->setSharedWith($room->getToken()) + ->setPermissions(\OCP\Constants::PERMISSION_READ); + + $this->shareManager->createShare($share); + + $message = json_encode([ + 'message' => 'file_shared', + 'parameters' => [ + 'share' => (string) $file->getId(), + 'metaData' => [ + 'mimeType' => $file->getMimeType(), + 'messageType' => $this->getTypeOfShare($file->getMimeType()), + ], + ], + ]); + + try { + $this->chatManager->addSystemMessage( + $room, + $participant->getAttendee()->getActorType(), + $participant->getAttendee()->getActorId(), + $message, + $creationDateTime, + true + ); + } catch (MessageTooLongException $e) { + throw new InvalidArgumentException('file-long-data'); + } catch (\Exception $e) { + throw new InvalidArgumentException('send-system-message'); + } + $this->notificationDismiss($room, $participant, $timestamp); + } } -- cgit v1.2.3 From b71fc1d3d9c99502db1e9b514c4d219592cccae3 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 18 Jan 2023 18:25:58 -0300 Subject: Prevent duplicate share Signed-off-by: Vitor Mattos --- lib/Chat/SystemMessage/Listener.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php index fecc384eb..9e33a8aca 100644 --- a/lib/Chat/SystemMessage/Listener.php +++ b/lib/Chat/SystemMessage/Listener.php @@ -382,6 +382,10 @@ class Listener implements IEventListener { $listener = Server::get(self::class); $manager = Server::get(Manager::class); + $request = Server::get(IRequest::class); + if ($request->getParam('_route') === 'ocs.spreed.Recording.shareToChat') { + return; + } $room = $manager->getRoomByToken($share->getSharedWith()); $metaData = Server::get(IRequest::class)->getParam('talkMetaData') ?? ''; $metaData = json_decode($metaData, true); -- cgit v1.2.3 From e529b71aa08c77d1e17ff021dbb33f9de4375746 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 18 Jan 2023 18:26:33 -0300 Subject: Fix share id Signed-off-by: Vitor Mattos --- lib/Service/RecordingService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index e74508cc3..e3f01bbfc 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -218,12 +218,12 @@ class RecordingService { ->setSharedWith($room->getToken()) ->setPermissions(\OCP\Constants::PERMISSION_READ); - $this->shareManager->createShare($share); + $share = $this->shareManager->createShare($share); $message = json_encode([ 'message' => 'file_shared', 'parameters' => [ - 'share' => (string) $file->getId(), + 'share' => $share->getId(), 'metaData' => [ 'mimeType' => $file->getMimeType(), 'messageType' => $this->getTypeOfShare($file->getMimeType()), -- cgit v1.2.3 From 2a1d71c3f8d0f69acdfad6279134839d1ddaa757 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 23 Jan 2023 13:17:35 -0300 Subject: Notify always https://github.com/nextcloud/spreed/pull/8550#discussion_r1084194777 Signed-off-by: Vitor Mattos --- lib/Service/RecordingService.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib') diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index e3f01bbfc..2e8abd6ed 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -160,10 +160,6 @@ class RecordingService { public function notifyStoredRecording(Room $room, Participant $participant, File $file): void { $attendee = $participant->getAttendee(); - $notificationLevel = $attendee->getNotificationLevel(); - if ($notificationLevel === Participant::NOTIFY_NEVER) { - return; - } $notification = $this->notificationManager->createNotification(); -- cgit v1.2.3 From 69060f003be6e1364f1748eb194887a1fab10791 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 23 Jan 2023 13:23:09 -0300 Subject: Convert permission from public page to no admin required https://github.com/nextcloud/spreed/pull/8550#discussion_r1084196825 Signed-off-by: Vitor Mattos --- lib/Controller/RecordingController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Controller/RecordingController.php b/lib/Controller/RecordingController.php index a1670c618..d5ed53fa0 100644 --- a/lib/Controller/RecordingController.php +++ b/lib/Controller/RecordingController.php @@ -102,7 +102,7 @@ class RecordingController extends AEnvironmentAwareController { } /** - * @PublicPage + * @NoAdminRequired * @RequireModeratorParticipant */ public function notificationDismiss(int $timestamp): DataResponse { @@ -119,7 +119,7 @@ class RecordingController extends AEnvironmentAwareController { } /** - * @PublicPage + * @NoAdminRequired * @RequireModeratorParticipant */ public function shareToChat(int $fileId, int $timestamp): DataResponse { -- cgit v1.2.3 From 9f1d38b0980a2fb8c7736922de6dc33666b27afe Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 23 Jan 2023 13:31:56 -0300 Subject: Fixes after code review https://github.com/nextcloud/spreed/pull/8550#discussion_r1084214748 https://github.com/nextcloud/spreed/pull/8550#discussion_r1084202960 https://github.com/nextcloud/spreed/pull/8550#discussion_r1084201311 Signed-off-by: Vitor Mattos --- lib/Service/RecordingService.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index 2e8abd6ed..0a7f7af2a 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -34,7 +34,6 @@ use OCA\Talk\Manager; use OCA\Talk\Participant; use OCA\Talk\Room; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\Comments\MessageTooLongException; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; @@ -177,7 +176,7 @@ class RecordingService { public function notificationDismiss(Room $room, Participant $participant, int $timestamp): void { $notification = $this->notificationManager->createNotification(); $notification->setApp('spreed') - ->setObject('chat', (string) $room->getToken()) + ->setObject('chat', $room->getToken()) ->setSubject('record_file_stored') ->setDateTime($this->timeFactory->getDateTime('@' . $timestamp)) ->setUser($participant->getAttendee()->getActorId()); @@ -185,8 +184,8 @@ class RecordingService { } private function getTypeOfShare(string $mimetype): string { - if (strpos($mimetype, 'video') !== false) { - return'record-video'; + if (str_starts_with($mimetype, 'video/')) { + return 'record-video'; } return 'record-audio'; } @@ -236,10 +235,8 @@ class RecordingService { $creationDateTime, true ); - } catch (MessageTooLongException $e) { - throw new InvalidArgumentException('file-long-data'); } catch (\Exception $e) { - throw new InvalidArgumentException('send-system-message'); + throw new InvalidArgumentException('system'); } $this->notificationDismiss($room, $participant, $timestamp); } -- cgit v1.2.3 From cca8617cd70298e205aa3a4f68dc174d73009f15 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 24 Jan 2023 15:21:46 +0100 Subject: Log the exception Signed-off-by: Joas Schilling --- lib/Service/RecordingService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index 0a7f7af2a..7a26c4ebb 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -43,6 +43,7 @@ use OCP\Files\NotPermittedException; use OCP\Notification\IManager; use OCP\Share\IManager as ShareManager; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; class RecordingService { public const DEFAULT_ALLOWED_RECORDING_FORMATS = [ @@ -61,7 +62,8 @@ class RecordingService { protected Config $config, protected RoomService $roomService, protected ShareManager $shareManager, - protected ChatManager $chatManager + protected ChatManager $chatManager, + protected LoggerInterface $logger, ) { } @@ -236,6 +238,7 @@ class RecordingService { true ); } catch (\Exception $e) { + $this->logger->error($e->getMessage(), ['exception' => $e]); throw new InvalidArgumentException('system'); } $this->notificationDismiss($room, $participant, $timestamp); -- cgit v1.2.3