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
19 changes: 19 additions & 0 deletions lib/Search/CurrentMessageSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Webinary;
use OCP\IUser;
use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
Expand Down Expand Up @@ -87,6 +89,23 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
);
}

try {
$participant = $room->getParticipant($user->getUID(), false);
} catch (ParticipantNotFoundException $e) {
return SearchResult::complete(
$this->l->t('Messages'),
[]
);
}

if ($room->getLobbyState() !== Webinary::LOBBY_NONE &&
!($participant->getPermissions() & Attendee::PERMISSIONS_LOBBY_IGNORE)) {
return SearchResult::complete(
$this->l->t('Messages'),
[]
);
}

$offset = (int) $query->getCursor();
$comments = $this->chatManager->searchForObjects(
$query->getTerm(),
Expand Down
8 changes: 8 additions & 0 deletions lib/Search/MessageSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\Talk\Manager as RoomManager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Webinary;
use OCP\Comments\IComment;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -126,6 +127,13 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
continue;
}

if ($room->getLobbyState() !== Webinary::LOBBY_NONE) {
$participant = $room->getParticipant($user->getUID(), false);
if (!($participant->getPermissions() & Attendee::PERMISSIONS_LOBBY_IGNORE)) {
continue;
}
}

$roomMap[(string) $room->getId()] = $room;
}

Expand Down
53 changes: 53 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
protected static $userToAttendeeId;
/** @var array[] */
protected static $messages;
/** @var int[] */
protected static $textToMessageId;


protected static $permissionsMap = [
Expand Down Expand Up @@ -1489,6 +1491,27 @@ public function userSeesTheFollowingMessagesInRoom($user, $identifier, $statusCo
$this->compareDataResponse($formData);
}

/**
* @Then /^user "([^"]*)" searches for "([^"]*)" in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*
* @param string $user
* @param string $search
* @param string $identifier
* @param string $statusCode
* @param string $apiVersion
*/
public function userSearchesInRoom(string $user, string $search, string $identifier, $statusCode, string $apiVersion = 'v1', TableNode $formData = null): void {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/search/providers/talk-message-current/search?term=' . $search . '&from=' . '/call/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, $statusCode);

if ($statusCode !== '200') {
return;
}

$this->compareSearchResponse($formData);
}

/**
* @Then /^user "([^"]*)" received a system messages in room "([^"]*)" to delete "([^"]*)"(?: \((v1)\))?$/
*
Expand Down Expand Up @@ -1587,6 +1610,36 @@ protected function compareDataResponse(TableNode $formData = null) {
}, $messages));
}

/**
* @param TableNode|null $formData
*/
protected function compareSearchResponse(TableNode $formData = null) {
$messages = $this->getDataFromResponse($this->response)['entries'];

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

$expected = array_map(static function (array $message) {
$message['attributes.conversation'] = self::$identifierToToken[$message['attributes.conversation']];
$message['attributes.messageId'] = self::$messages[$message['attributes.messageId']];
return $message;
}, $formData->getHash());

$count = count($expected);
Assert::assertCount($count, $messages, 'Message count does not match');

Assert::assertEquals($expected, array_map(static function ($message) {
return [
'title' => $message['title'],
'subline' => $message['subline'],
'attributes.conversation' => $message['attributes']['conversation'],
'attributes.messageId' => $message['attributes']['messageId'],
];
}, $messages));
}

/**
* @Then /^user "([^"]*)" sees the following system messages in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/features/chat/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Feature: chat/search
Background:
Given user "participant1" exists
Given user "participant2" exists

Scenario: Can not search when not a participant
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| roomName | room |
And user "participant1" sends message "Message 1" to room "room" with 201
When user "participant2" searches for "essa" in room "room" with 200

Scenario: Search for message when being a participant
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| roomName | room |
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
And user "participant1" sends message "Message 1" to room "room" with 201
When user "participant2" searches for "essa" in room "room" with 200
| title | subline | attributes.conversation | attributes.messageId |
| participant1-displayname | Message 1 | room | Message 1 |

Scenario: Can not search when being blocked by the lobby
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| roomName | room |
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
And user "participant1" sends message "Message 1" to room "room" with 201
And user "participant1" sets lobby state for room "room" to "non moderators" with 200 (v4)
When user "participant2" searches for "essa" in room "room" with 200