mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(comments): use showFile route to reference files with a matching comment
The files.view.index route with dir and scrollto is deprecated and opening the actual does not work anymore. Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
parent
478b0123b8
commit
a37ed05b8f
4 changed files with 24 additions and 10 deletions
|
|
@ -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()))
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -61,9 +62,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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class Result extends BaseResult {
|
|||
* @deprecated 20.0.0
|
||||
*/
|
||||
public $fileName;
|
||||
/**
|
||||
* @deprecated 20.0.0
|
||||
*/
|
||||
public int $fileId;
|
||||
|
||||
/**
|
||||
* @throws NotFoundException
|
||||
|
|
@ -47,6 +51,7 @@ class Result extends BaseResult {
|
|||
*/
|
||||
public string $authorName,
|
||||
string $path,
|
||||
int $fileId,
|
||||
) {
|
||||
parent::__construct(
|
||||
$comment->getId(),
|
||||
|
|
@ -58,6 +63,7 @@ class Result extends BaseResult {
|
|||
$this->authorId = $comment->getActorId();
|
||||
$this->fileName = basename($path);
|
||||
$this->path = $this->getVisiblePath($path);
|
||||
$this->fileId = $fileId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@
|
|||
<code><![CDATA[$result->authorId]]></code>
|
||||
<code><![CDATA[$result->authorId]]></code>
|
||||
<code><![CDATA[$result->authorId]]></code>
|
||||
<code><![CDATA[$result->fileId]]></code>
|
||||
<code><![CDATA[$result->fileId]]></code>
|
||||
<code><![CDATA[$result->name]]></code>
|
||||
<code><![CDATA[$result->path]]></code>
|
||||
</DeprecatedProperty>
|
||||
|
|
@ -81,7 +83,8 @@
|
|||
<code><![CDATA[new Result($query,
|
||||
$comment,
|
||||
$displayName,
|
||||
$file->getPath()
|
||||
$file->getPath(),
|
||||
$file->getId(),
|
||||
)]]></code>
|
||||
</DeprecatedClass>
|
||||
<DeprecatedMethod>
|
||||
|
|
@ -108,6 +111,7 @@
|
|||
<DeprecatedProperty>
|
||||
<code><![CDATA[$this->authorId]]></code>
|
||||
<code><![CDATA[$this->comment]]></code>
|
||||
<code><![CDATA[$this->fileId]]></code>
|
||||
<code><![CDATA[$this->fileName]]></code>
|
||||
<code><![CDATA[$this->path]]></code>
|
||||
</DeprecatedProperty>
|
||||
|
|
|
|||
Loading…
Reference in a new issue