Skip to content

Commit 347f10b

Browse files
authored
Merge pull request #54829 from nextcloud/backport/54826/stable31
[stable31] fix(comments): use showFile route to reference files with a matching …
2 parents 785f509 + 59a901c commit 347f10b

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

apps/comments/lib/Search/CommentsSearchProvider.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use OCP\Search\SearchResult;
1818
use OCP\Search\SearchResultEntry;
1919
use function array_map;
20-
use function pathinfo;
2120

2221
class CommentsSearchProvider implements IProvider {
2322
public function __construct(
@@ -49,22 +48,25 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
4948
$this->l10n->t('Comments'),
5049
array_map(function (Result $result) {
5150
$path = $result->path;
52-
$pathInfo = pathinfo($path);
5351
$isUser = $this->userManager->userExists($result->authorId);
5452
$avatarUrl = $isUser
5553
? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42])
5654
: $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]);
57-
return new SearchResultEntry(
55+
$link = $this->urlGenerator->linkToRoute(
56+
'files.View.showFile',
57+
['fileid' => $result->fileId]
58+
);
59+
$searchResultEntry = new SearchResultEntry(
5860
$avatarUrl,
5961
$result->name,
6062
$path,
61-
$this->urlGenerator->linkToRouteAbsolute('files.view.index', [
62-
'dir' => $pathInfo['dirname'],
63-
'scrollto' => $pathInfo['basename'],
64-
]),
63+
$link,
6564
'',
6665
true
6766
);
67+
$searchResultEntry->addAttribute('fileId', (string)$result->fileId);
68+
$searchResultEntry->addAttribute('path', $path);
69+
return $searchResultEntry;
6870
}, $this->legacyProvider->search($query->getTerm()))
6971
);
7072
}

apps/comments/lib/Search/LegacyProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCP\Comments\IComment;
1212
use OCP\Comments\ICommentsManager;
1313
use OCP\Files\Folder;
14+
use OCP\Files\InvalidPathException;
1415
use OCP\Files\Node;
1516
use OCP\Files\NotFoundException;
1617
use OCP\IUser;
@@ -59,9 +60,10 @@ public function search($query): array {
5960
$result[] = new Result($query,
6061
$comment,
6162
$displayName,
62-
$file->getPath()
63+
$file->getPath(),
64+
$file->getId(),
6365
);
64-
} catch (NotFoundException $e) {
66+
} catch (NotFoundException|InvalidPathException $e) {
6567
continue;
6668
}
6769
}

apps/comments/lib/Search/Result.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class Result extends BaseResult {
3333
* @deprecated 20.0.0
3434
*/
3535
public $fileName;
36+
/**
37+
* @deprecated 20.0.0
38+
*/
39+
public int $fileId;
3640

3741
/**
3842
* @throws NotFoundException
@@ -46,6 +50,7 @@ public function __construct(
4650
*/
4751
public string $authorName,
4852
string $path,
53+
int $fileId,
4954
) {
5055
parent::__construct(
5156
$comment->getId(),
@@ -57,6 +62,7 @@ public function __construct(
5762
$this->authorId = $comment->getActorId();
5863
$this->fileName = basename($path);
5964
$this->path = $this->getVisiblePath($path);
65+
$this->fileId = $fileId;
6066
}
6167

6268
/**

0 commit comments

Comments
 (0)