diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/RecordingController.php | 26 | ||||
-rw-r--r-- | lib/Notification/Notifier.php | 32 | ||||
-rw-r--r-- | lib/Service/RecordingService.php | 92 |
3 files changed, 119 insertions, 31 deletions
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); + } } |