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: 9 additions & 7 deletions apps/comments/lib/Search/CommentsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use OCP\Search\SearchResult;
use OCP\Search\SearchResultEntry;
use function array_map;
use function pathinfo;

class CommentsSearchProvider implements IProvider {
public function __construct(
Expand Down Expand Up @@ -49,22 +48,25 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$this->l10n->t('Comments'),
array_map(function (Result $result) {
$path = $result->path;
$pathInfo = pathinfo($path);
$isUser = $this->userManager->userExists($result->authorId);
$avatarUrl = $isUser
? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42])
: $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]);
return new SearchResultEntry(
$link = $this->urlGenerator->linkToRoute(
'files.View.showFile',
['fileid' => $result->fileId]
);
$searchResultEntry = new SearchResultEntry(
$avatarUrl,
$result->name,
$path,
$this->urlGenerator->linkToRouteAbsolute('files.view.index', [
'dir' => $pathInfo['dirname'],
'scrollto' => $pathInfo['basename'],
]),
$link,
'',
true
);
$searchResultEntry->addAttribute('fileId', (string)$result->fileId);
$searchResultEntry->addAttribute('path', $path);
return $searchResultEntry;
}, $this->legacyProvider->search($query->getTerm()))
);
}
Expand Down
6 changes: 4 additions & 2 deletions apps/comments/lib/Search/LegacyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Files\Folder;
use OCP\Files\InvalidPathException;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IUser;
Expand Down Expand Up @@ -59,9 +60,10 @@ public function search($query): array {
$result[] = new Result($query,
$comment,
$displayName,
$file->getPath()
$file->getPath(),
$file->getId(),
);
} catch (NotFoundException $e) {
} catch (NotFoundException|InvalidPathException $e) {
continue;
}
}
Expand Down
6 changes: 6 additions & 0 deletions apps/comments/lib/Search/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Result extends BaseResult {
* @deprecated 20.0.0
*/
public $fileName;
/**
* @deprecated 20.0.0
*/
public int $fileId;

/**
* @throws NotFoundException
Expand All @@ -46,6 +50,7 @@ public function __construct(
*/
public string $authorName,
string $path,
int $fileId,
) {
parent::__construct(
$comment->getId(),
Expand All @@ -57,6 +62,7 @@ public function __construct(
$this->authorId = $comment->getActorId();
$this->fileName = basename($path);
$this->path = $this->getVisiblePath($path);
$this->fileId = $fileId;
}

/**
Expand Down
Loading