diff options
author | Joas Schilling <coding@schilljs.com> | 2022-03-31 10:31:15 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-31 16:05:34 +0300 |
commit | 7b66c817fe3cbfe65689366591976ee698dee534 (patch) | |
tree | 12f8e207a78521c38563ed5dc191edd157cc5c04 /lib/Chat/ChatManager.php | |
parent | 5278e716c7e45c0751257cc0b14db1fbe344f40b (diff) |
Use attachment service to store and retrieve shared items
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Chat/ChatManager.php')
-rw-r--r-- | lib/Chat/ChatManager.php | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 7340f0a5f..62522bcd6 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -31,6 +31,7 @@ use OCA\Talk\Events\ChatParticipantEvent; use OCA\Talk\Model\Attendee; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCA\Talk\Service\AttachmentService; use OCA\Talk\Service\ParticipantService; use OCA\Talk\Share\RoomShareProvider; use OCP\AppFramework\Utility\ITimeFactory; @@ -91,6 +92,7 @@ class ChatManager { protected $cache; /** @var ICache */ protected $unreadCountCache; + protected AttachmentService $attachmentService; public function __construct(CommentsManager $commentsManager, IEventDispatcher $dispatcher, @@ -101,7 +103,8 @@ class ChatManager { ParticipantService $participantService, Notifier $notifier, ICacheFactory $cacheFactory, - ITimeFactory $timeFactory) { + ITimeFactory $timeFactory, + AttachmentService $attachmentService) { $this->commentsManager = $commentsManager; $this->dispatcher = $dispatcher; $this->connection = $connection; @@ -113,6 +116,7 @@ class ChatManager { $this->cache = $cacheFactory->createDistributed('talk/lastmsgid'); $this->unreadCountCache = $cacheFactory->createDistributed('talk/unreadcount'); $this->timeFactory = $timeFactory; + $this->attachmentService = $attachmentService; } /** @@ -186,6 +190,10 @@ class ChatManager { } $this->cache->remove($chat->getToken()); + if ($messageType === 'object_shared' || $messageType === 'file_shared') { + $this->attachmentService->createAttachmentEntry($chat, $comment, $messageType, $messageDecoded['parameters'] ?? []); + } + return $comment; } @@ -617,19 +625,18 @@ class ChatManager { * Search for comments with a given content * * @param Room $chat - * @param int $offset - * @param int $limit + * @param int[]$commentIds * @return IComment[] */ - public function getSharedObjectMessages(Room $chat, int $offset, int $limit): array { - return $this->commentsManager->getCommentsWithVerbForObjectSinceComment( - 'chat', - (string) $chat->getId(), - ['object_shared'], - $offset, - 'desc', - $limit - ); + public function getMessagesById(Room $chat, array $commentIds): array { + $comments = $this->commentsManager->getCommentsById($commentIds); + + $comments = array_filter($comments, static function (IComment $comment) use ($chat) { + return $comment->getObjectType() === 'chat' + && $comment->getObjectId() === $chat->getId(); + }); + + return $comments; } /** |