diff options
author | Joas Schilling <coding@schilljs.com> | 2023-10-16 16:31:39 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-10-16 16:31:39 +0200 |
commit | 4799578e9d839116945e3ba0245a477a4c2bf102 (patch) | |
tree | b00dc42824937e580a3742099f1c6f146c036266 | |
parent | d627cac285c9d7663fcba539d5cea9c4ec799e89 (diff) |
FIXME Attempt to start attachments table entriesfeat/noid/multi-file-support
-rw-r--r-- | lib/Chat/ChatManager.php | 2 | ||||
-rw-r--r-- | lib/Controller/ChatController.php | 2 | ||||
-rw-r--r-- | lib/Service/AttachmentService.php | 34 |
3 files changed, 36 insertions, 2 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 503c8e74f..350e80653 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -191,6 +191,8 @@ class ChatManager { if ($messageType === 'object_shared' || $messageType === 'file_shared') { $this->attachmentService->createAttachmentEntry($chat, $comment, $messageType, $messageDecoded['parameters'] ?? []); + } elseif ($messageType === 'multiple_files_shared') { + $this->attachmentService->createAttachmentEntriesForAllShares($chat, $comment, $messageDecoded['parameters'] ?? []); } return $comment; diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index d4931f2bd..54c92123f 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -308,7 +308,7 @@ class ChatController extends AEnvironmentAwareController { /** * Share multiple files and a caption into the chat * - * @param int[] $shareIds The share IDs that should be shown with this message + * @param string[] $shareIds The share IDs that should be shown with this message * @param string $caption The message to send * @param string $actorDisplayName for guests * @param string $referenceId for the message to be able to later identify it again diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index 0a935d791..dcfb93be8 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -29,12 +29,14 @@ namespace OCA\Talk\Service; use OCA\Talk\Model\Attachment; use OCA\Talk\Model\AttachmentMapper; use OCA\Talk\Room; +use OCA\Talk\Share\RoomShareProvider; use OCP\Comments\IComment; class AttachmentService { public function __construct( - public AttachmentMapper $attachmentMapper, + protected AttachmentMapper $attachmentMapper, + protected RoomShareProvider $shareProvider, ) { } @@ -81,6 +83,36 @@ class AttachmentService { /** * @param Room $room + * @param IComment $comment + * @param array{shares?: string[], caption?: string} $parameters + */ + public function createAttachmentEntriesForAllShares(Room $room, IComment $comment, array $parameters): void { + + $shares = $this->shareProvider->getSharesByIds($parameters['shares']); + foreach ($shares as $share) { + $mimetype = $share->getNode()->getMimeType(); + + $attachment = new Attachment(); + $attachment->setRoomId($room->getId()); + $attachment->setActorType($comment->getActorType()); + $attachment->setActorId($comment->getActorId()); + $attachment->setMessageId((int) $comment->getId()); + $attachment->setMessageTime($comment->getCreationDateTime()->getTimestamp()); + + if (str_starts_with($mimetype, 'audio/')) { + $attachment->setObjectType(Attachment::TYPE_AUDIO); + } elseif (str_starts_with($mimetype, 'image/') || str_starts_with($mimetype, 'video/')) { + $attachment->setObjectType(Attachment::TYPE_MEDIA); + } else { + $attachment->setObjectType(Attachment::TYPE_FILE); + } + + $this->attachmentMapper->insert($attachment); + } + } + + /** + * @param Room $room * @param string $objectType * @param int $offset * @param int $limit |