Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/Collaboration/Collaborators/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\TalkSession;
use OCP\Collaboration\AutoComplete\AutoCompleteEvent;
use OCP\Collaboration\AutoComplete\IManager;
use OCP\EventDispatcher\IEventDispatcher;
Expand All @@ -44,19 +45,25 @@ class Listener {
protected IUserManager $userManager;
protected ParticipantService $participantService;
protected Config $config;
protected TalkSession $talkSession;
/** @var string[] */
protected array $allowedGroupIds = [];
protected string $roomToken;
protected ?Room $room = null;
protected ?string $userId;

public function __construct(Manager $manager,
IUserManager $userManager,
ParticipantService $participantService,
Config $config) {
Config $config,
TalkSession $talkSession,
?string $userId) {
$this->manager = $manager;
$this->userManager = $userManager;
$this->participantService = $participantService;
$this->talkSession = $talkSession;
$this->config = $config;
$this->userId = $userId;
}

public static function register(IEventDispatcher $dispatcher): void {
Expand Down Expand Up @@ -122,10 +129,14 @@ protected function filterBridgeBot(array $results): array {
}

protected function filterExistingParticipants(string $token, array $results): array {
$sessionId = $this->talkSession->getSessionForRoom($token);
try {
$this->room = $this->manager->getRoomByToken($token);
$this->room = $this->manager->getRoomForUserByToken($token, $this->userId);
$this->participantService->getParticipant($this->room, $this->userId, $sessionId);
} catch (RoomNotFoundException $e) {
return $results;
} catch (ParticipantNotFoundException $e) {
return $results;
}

if (!empty($results['groups'])) {
Expand Down
48 changes: 48 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,54 @@ public function userGetsTheFollowingCandidateMentionsInRoomFor($user, $identifie
}
}

/**
* @Then /^user "([^"]*)" gets the following collaborator suggestions in room "([^"]*)" for "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $identifier
* @param string $search
* @param string $statusCode
* @param string $apiVersion
* @param TableNode|null $formData
*/
public function userGetsTheFollowingCollaboratorSuggestions($user, $identifier, $search, $statusCode, $apiVersion = 'v1', TableNode $formData = null) {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/core/autocomplete/get?search=' . $search . '&itemType=call&itemId=' . self::$identifierToToken[$identifier] . '&shareTypes[]=0&shareTypes[]=1&shareTypes[]=7&shareTypes[]=4');
$this->assertStatusCode($this->response, $statusCode);

$mentions = $this->getDataFromResponse($this->response);

if ($formData === null) {
Assert::assertEmpty($mentions);
return;
}

Assert::assertCount(count($formData->getHash()), $mentions, 'Mentions count does not match');

usort($mentions, function ($a, $b) {
if ($a['source'] === $b['source']) {
return $a['label'] <=> $b['label'];
}
return $a['source'] <=> $b['source'];
});

$expected = $formData->getHash();
usort($expected, function ($a, $b) {
if ($a['source'] === $b['source']) {
return $a['label'] <=> $b['label'];
}
return $a['source'] <=> $b['source'];
});

foreach ($expected as $key => $row) {
unset($mentions[$key]['icon']);
unset($mentions[$key]['status']);
unset($mentions[$key]['subline']);
unset($mentions[$key]['shareWithDisplayNameUnique']);
Assert::assertEquals($row, $mentions[$key]);
}
}

/**
* @Then /^guest "([^"]*)" sets name to "([^"]*)" in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/features/conversation/add-participant.feature
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,46 @@ Feature: conversation/add-participant
| users | participant1 | 1 |
And user "participant2" is not participant of room "room" (v4)
And user "participant3" is not participant of room "room" (v4)

Scenario: Getting participant suggestions in a private room
Given user "participant1" creates room "room" (v4)
| roomType | 2 |
| roomName | room |
And user "participant1" gets the following collaborator suggestions in room "room" for "particip" with 200
| source | id | label |
| users | participant2 | participant2-displayname |
| users | participant3 | participant3-displayname |
And user "participant1" gets the following collaborator suggestions in room "room" for "participant2" with 200
| source | id | label |
| users | participant2 | participant2-displayname |
And user "participant3" gets the following collaborator suggestions in room "room" for "participant2" with 200
| source | id | label |
| users | participant2 | participant2-displayname |
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
And user "participant1" gets the following collaborator suggestions in room "room" for "participant2" with 200
And user "participant3" gets the following collaborator suggestions in room "room" for "participant2" with 200
| source | id | label |
| users | participant2 | participant2-displayname |

Scenario: Getting participant suggestions in a public room
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| roomName | room |
And user "participant1" gets the following collaborator suggestions in room "room" for "particip" with 200
| source | id | label |
| users | participant2 | participant2-displayname |
| users | participant3 | participant3-displayname |
And user "participant1" gets the following collaborator suggestions in room "room" for "participant2" with 200
| source | id | label |
| users | participant2 | participant2-displayname |
And user "participant3" gets the following collaborator suggestions in room "room" for "participant2" with 200
| source | id | label |
| users | participant2 | participant2-displayname |
And user "guest" joins room "room" with 200 (v4)
And user "guest" gets the following collaborator suggestions in room "room" for "participant2" with 401
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
And user "participant1" gets the following collaborator suggestions in room "room" for "participant2" with 200
And user "participant3" gets the following collaborator suggestions in room "room" for "participant2" with 200
| source | id | label |
| users | participant2 | participant2-displayname |
And user "guest" gets the following collaborator suggestions in room "room" for "participant2" with 401