Merge pull request #54828 from nextcloud/backport/54826/stable30

[stable30] fix(comments): use showFile route to reference files with a matching …
This commit is contained in:
Andy Scherzinger 2025-09-03 13:37:09 +02:00 committed by GitHub
commit 9771be2ed7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View file

@ -17,7 +17,6 @@ use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
use OCP\Search\SearchResultEntry;
use function array_map;
use function pathinfo;
class CommentsSearchProvider implements IProvider {
public function __construct(
@ -49,22 +48,25 @@ class CommentsSearchProvider implements IProvider {
$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()))
);
}

View file

@ -11,6 +11,7 @@ namespace OCA\Comments\Search;
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;
@ -59,9 +60,10 @@ class LegacyProvider extends Provider {
$result[] = new Result($query,
$comment,
$displayName,
$file->getPath()
$file->getPath(),
$file->getId(),
);
} catch (NotFoundException $e) {
} catch (NotFoundException|InvalidPathException $e) {
continue;
}
}

View file

@ -38,6 +38,10 @@ class Result extends BaseResult {
* @deprecated 20.0.0
*/
public $fileName;
/**
* @deprecated 20.0.0
*/
public int $fileId;
/**
* @throws NotFoundException
@ -48,6 +52,7 @@ class Result extends BaseResult {
IComment $comment,
string $authorName,
string $path,
int $fileId,
) {
parent::__construct(
$comment->getId(),
@ -60,6 +65,7 @@ class Result extends BaseResult {
$this->authorName = $authorName;
$this->fileName = basename($path);
$this->path = $this->getVisiblePath($path);
$this->fileId = $fileId;
}
/**