From 20d376669e7f2fa3b0e578250071dbe5f8c25f40 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 14 Nov 2022 21:29:42 -0300 Subject: [PATCH] Return conversation avatar in mentions Signed-off-by: Vitor Mattos --- lib/Chat/ChatManager.php | 7 ++++++- tests/integration/features/bootstrap/FeatureContext.php | 5 +++++ tests/integration/features/chat/avatar.feature | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 1ce33fed05..627032e4e3 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -34,6 +34,7 @@ use OCA\Talk\Model\Poll; use OCA\Talk\Participant; use OCA\Talk\Room; use OCA\Talk\Service\AttachmentService; +use OCA\Talk\Service\AvatarService; use OCA\Talk\Service\ParticipantService; use OCA\Talk\Service\PollService; use OCA\Talk\Service\RoomService; @@ -94,6 +95,7 @@ class ChatManager { private RoomService $roomService; private PollService $pollService; private Notifier $notifier; + private AvatarService $avatarService; protected ITimeFactory $timeFactory; protected ICache $cache; protected ICache $unreadCountCache; @@ -110,6 +112,7 @@ class ChatManager { RoomService $roomService, PollService $pollService, Notifier $notifier, + AvatarService $avatarService, ICacheFactory $cacheFactory, ITimeFactory $timeFactory, AttachmentService $attachmentService, @@ -124,6 +127,7 @@ class ChatManager { $this->roomService = $roomService; $this->pollService = $pollService; $this->notifier = $notifier; + $this->avatarService = $avatarService; $this->cache = $cacheFactory->createDistributed('talk/lastmsgid'); $this->unreadCountCache = $cacheFactory->createDistributed('talk/unreadcount'); $this->timeFactory = $timeFactory; @@ -757,7 +761,8 @@ class ChatManager { array_unshift($results, [ 'id' => 'all', 'label' => $roomDisplayName, - 'source' => 'calls' + 'source' => 'calls', + 'avatar' => $this->avatarService->getAvatarUrl($room), ]); } return $results; diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index fed319cc56..3bef89a99b 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -2233,6 +2233,11 @@ class FeatureContext implements Context, SnippetAcceptingContext { Assert::assertRegExp('/^guest\/[0-9a-f]{40}$/', $mentions[$key]['id']); $mentions[$key]['id'] = 'GUEST_ID'; } + if (array_key_exists('avatar', $row)) { + Assert::assertRegExp('/' . self::$identifierToToken[$row['avatar']] . '\/avatar/', $mentions[$key]['avatar']); + unset($row['avatar']); + } + unset($mentions[$key]['avatar'], ); Assert::assertEquals($row, $mentions[$key]); } } diff --git a/tests/integration/features/chat/avatar.feature b/tests/integration/features/chat/avatar.feature index 4f7c55ae84..69629bf837 100644 --- a/tests/integration/features/chat/avatar.feature +++ b/tests/integration/features/chat/avatar.feature @@ -36,3 +36,12 @@ Feature: chat/avatar | roomType | 1 | | invite | participant2 | Then user "participant1" send the file "/img/favicon.png" as avatar of room "room2" with 404 + + Scenario: get mentions in a group room with no other participant + When user "participant1" creates room "group room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" send the file "/img/favicon.png" as avatar of room "group room" with 200 + Then user "participant1" gets the following candidate mentions in room "group room" for "" with 200 + | id | label | source | avatar | + | all | room | calls | group room |