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
16 changes: 15 additions & 1 deletion lib/Search/MessageSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\ThreadService;
use OCA\Talk\Webinary;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\IL10N;
Expand Down Expand Up @@ -50,6 +52,7 @@ public function __construct(
protected IL10N $l,
protected Config $talkConfig,
protected IUserSession $userSession,
protected ThreadService $threadService,
) {
}

Expand Down Expand Up @@ -282,6 +285,12 @@ protected function commentToSearchResultEntry(Room $room, IUser $user, IComment
}
}

$threadId = (int)$comment->getTopmostParentId() ?: (int)$comment->getId();
try {
$thread = $this->threadService->findByThreadId($room->getId(), $threadId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does a query per search result.
Should be moved to a prepare step like we do in other places (same problem there is share loading)

} catch (DoesNotExistException) {
$thread = null;
}
$entry = new SearchResultEntry(
$iconUrl,
str_replace(
Expand All @@ -290,13 +299,18 @@ protected function commentToSearchResultEntry(Room $room, IUser $user, IComment
$subline
),
$messageStr,
$this->url->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]) . '#message_' . $comment->getId(),
$this->url->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()])
. ($thread !== null ? '?threadId=' . $thread->getId() : '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how we build URLs in PHP, but I will fix it in #15880 where the same thing was introduced for a second place

. '#message_' . $comment->getId(),
'icon-talk', // $iconClass,
true
);

$entry->addAttribute('conversation', $room->getToken());
$entry->addAttribute('messageId', $comment->getId());
if ($thread !== null) {
$entry->addAttribute('threadId', (string)$thread->getId());
}
$entry->addAttribute('actorType', $comment->getActorType());
$entry->addAttribute('actorId', $comment->getActorId());
$entry->addAttribute('timestamp', '' . $comment->getCreationDateTime()->getTimestamp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,15 @@ async function fetchSearchResults(isNew = true): Promise<void> {
}

searchResults.value = searchResults.value.concat(entries.map((entry: UnifiedSearchResultEntry) => {
const threadId = (entry.attributes.threadId !== entry.attributes.messageId) ? entry.attributes.threadId : undefined

return {
...entry,
to: {
name: 'conversation',
hash: `#message_${entry.attributes.messageId}`,
params: { token: entry.attributes.conversation },
query: { threadId },
},
}
}))
Expand Down
1 change: 1 addition & 0 deletions src/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type AutocompleteResponse = ApiResponse<operationsCore['auto_complete-get
type MessageSearchResultAttributes = {
conversation: string
messageId: string
threadId: string
actorType: string
actorId: string
timestamp: string
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2795,6 +2795,9 @@ protected function compareSearchResponse(?TableNode $formData = null, ?string $e
if (isset($result['attributes.conversation'])) {
$result['attributes.conversation'] = self::$identifierToToken[$result['attributes.conversation']];
}
if (isset($result['attributes.threadId'])) {
$result['attributes.threadId'] = self::$titleToThreadId[$result['attributes.threadId']];
}
if (isset($result['attributes.messageId'])) {
$result['attributes.messageId'] = self::$textToMessageId[$result['attributes.messageId']];
}
Expand All @@ -2815,6 +2818,9 @@ protected function compareSearchResponse(?TableNode $formData = null, ?string $e
if (isset($actual['attributes']['messageId'])) {
$compare['attributes.messageId'] = $actual['attributes']['messageId'];
}
if (isset($actual['attributes']['threadId'])) {
$compare['attributes.threadId'] = $actual['attributes']['threadId'];
}
return $compare;
}, $results));
}
Expand Down
14 changes: 11 additions & 3 deletions tests/integration/features/chat-4/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ Feature: chat-2/search
And user "participant1" adds user "participant2" to room "room2" with 200 (v4)
And user "participant1" sends message "Message 1" to room "room1" with 201
And user "participant1" sends message "Message 2" to room "room2" with 201
And user "participant1" sends thread "Thread 1" with message "Thread 1" to room "room1" with 201
And user "participant2" sends reply "Thread 1-1" on thread "Thread 1" to room "room1" with 201
When user "participant1" shares "welcome.txt" with room "room1"
| talkMetaData | {"caption":"Message 3"} |
Then user "participant1" sees the following messages in room "room1" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters |
| room1 | users | participant1 | participant1-displayname | Message 3 | "IGNORE" |
| room1 | users | participant1 | participant1-displayname | Message 1 | [] |
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room1 | users | participant1 | participant1-displayname | Message 3 | "IGNORE" | |
| room1 | users | participant2 | participant2-displayname | Thread 1-1 | [] | Thread 1 |
| room1 | users | participant1 | participant1-displayname | Thread 1 | [] | |
| room1 | users | participant1 | participant1-displayname | Message 1 | [] | |
When user "participant2" searches for messages with "essa" in room "room1" with 200
| title | subline | attributes.conversation | attributes.messageId |
| participant1-displayname | Message 3 | room1 | Message 3 |
Expand All @@ -44,6 +48,10 @@ Feature: chat-2/search
| title | subline | attributes.conversation | attributes.messageId |
| participant1-displayname | Message 3 | room1 | Message 3 |
| participant1-displayname | Message 1 | room1 | Message 1 |
When user "participant2" searches for messages with "read" in room "room1" with 200
| title | subline | attributes.conversation | attributes.threadId | attributes.messageId |
| participant2-displayname | Thread 1-1 | room1 | Thread 1 | Thread 1-1 |
| participant1-displayname | Thread 1 | room1 | Thread 1 | Thread 1 |

Scenario: Can not search when being blocked by the lobby
Given user "participant1" creates room "room" (v4)
Expand Down
Loading