@@ -14,98 +14,98 @@ |
||
14 | 14 | * @deprecated 20.0.0 |
15 | 15 | */ |
16 | 16 | class Result extends BaseResult { |
17 | - /** |
|
18 | - * @deprecated 20.0.0 |
|
19 | - */ |
|
20 | - public $type = 'comment'; |
|
21 | - /** |
|
22 | - * @deprecated 20.0.0 |
|
23 | - */ |
|
24 | - public $comment; |
|
25 | - /** |
|
26 | - * @deprecated 20.0.0 |
|
27 | - */ |
|
28 | - public $authorId; |
|
29 | - /** |
|
30 | - * @deprecated 20.0.0 |
|
31 | - */ |
|
32 | - public $path; |
|
33 | - /** |
|
34 | - * @deprecated 20.0.0 |
|
35 | - */ |
|
36 | - public $fileName; |
|
37 | - /** |
|
38 | - * @deprecated 20.0.0 |
|
39 | - */ |
|
40 | - public int $fileId; |
|
17 | + /** |
|
18 | + * @deprecated 20.0.0 |
|
19 | + */ |
|
20 | + public $type = 'comment'; |
|
21 | + /** |
|
22 | + * @deprecated 20.0.0 |
|
23 | + */ |
|
24 | + public $comment; |
|
25 | + /** |
|
26 | + * @deprecated 20.0.0 |
|
27 | + */ |
|
28 | + public $authorId; |
|
29 | + /** |
|
30 | + * @deprecated 20.0.0 |
|
31 | + */ |
|
32 | + public $path; |
|
33 | + /** |
|
34 | + * @deprecated 20.0.0 |
|
35 | + */ |
|
36 | + public $fileName; |
|
37 | + /** |
|
38 | + * @deprecated 20.0.0 |
|
39 | + */ |
|
40 | + public int $fileId; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @throws NotFoundException |
|
44 | - * @deprecated 20.0.0 |
|
45 | - */ |
|
46 | - public function __construct( |
|
47 | - string $search, |
|
48 | - IComment $comment, |
|
49 | - /** |
|
50 | - * @deprecated 20.0.0 |
|
51 | - */ |
|
52 | - public string $authorName, |
|
53 | - string $path, |
|
54 | - int $fileId, |
|
55 | - ) { |
|
56 | - parent::__construct( |
|
57 | - $comment->getId(), |
|
58 | - $comment->getMessage() |
|
59 | - /* @todo , [link to file] */ |
|
60 | - ); |
|
42 | + /** |
|
43 | + * @throws NotFoundException |
|
44 | + * @deprecated 20.0.0 |
|
45 | + */ |
|
46 | + public function __construct( |
|
47 | + string $search, |
|
48 | + IComment $comment, |
|
49 | + /** |
|
50 | + * @deprecated 20.0.0 |
|
51 | + */ |
|
52 | + public string $authorName, |
|
53 | + string $path, |
|
54 | + int $fileId, |
|
55 | + ) { |
|
56 | + parent::__construct( |
|
57 | + $comment->getId(), |
|
58 | + $comment->getMessage() |
|
59 | + /* @todo , [link to file] */ |
|
60 | + ); |
|
61 | 61 | |
62 | - $this->comment = $this->getRelevantMessagePart($comment->getMessage(), $search); |
|
63 | - $this->authorId = $comment->getActorId(); |
|
64 | - $this->fileName = basename($path); |
|
65 | - $this->path = $this->getVisiblePath($path); |
|
66 | - $this->fileId = $fileId; |
|
67 | - } |
|
62 | + $this->comment = $this->getRelevantMessagePart($comment->getMessage(), $search); |
|
63 | + $this->authorId = $comment->getActorId(); |
|
64 | + $this->fileName = basename($path); |
|
65 | + $this->path = $this->getVisiblePath($path); |
|
66 | + $this->fileId = $fileId; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @throws NotFoundException |
|
71 | - */ |
|
72 | - protected function getVisiblePath(string $path): string { |
|
73 | - $segments = explode('/', trim($path, '/'), 3); |
|
69 | + /** |
|
70 | + * @throws NotFoundException |
|
71 | + */ |
|
72 | + protected function getVisiblePath(string $path): string { |
|
73 | + $segments = explode('/', trim($path, '/'), 3); |
|
74 | 74 | |
75 | - if (!isset($segments[2])) { |
|
76 | - throw new NotFoundException('Path not inside visible section'); |
|
77 | - } |
|
75 | + if (!isset($segments[2])) { |
|
76 | + throw new NotFoundException('Path not inside visible section'); |
|
77 | + } |
|
78 | 78 | |
79 | - return $segments[2]; |
|
80 | - } |
|
79 | + return $segments[2]; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @throws NotFoundException |
|
84 | - */ |
|
85 | - protected function getRelevantMessagePart(string $message, string $search): string { |
|
86 | - $start = mb_stripos($message, $search); |
|
87 | - if ($start === false) { |
|
88 | - throw new NotFoundException('Comment section not found'); |
|
89 | - } |
|
82 | + /** |
|
83 | + * @throws NotFoundException |
|
84 | + */ |
|
85 | + protected function getRelevantMessagePart(string $message, string $search): string { |
|
86 | + $start = mb_stripos($message, $search); |
|
87 | + if ($start === false) { |
|
88 | + throw new NotFoundException('Comment section not found'); |
|
89 | + } |
|
90 | 90 | |
91 | - $end = $start + mb_strlen($search); |
|
91 | + $end = $start + mb_strlen($search); |
|
92 | 92 | |
93 | - if ($start <= 25) { |
|
94 | - $start = 0; |
|
95 | - $prefix = ''; |
|
96 | - } else { |
|
97 | - $start -= 25; |
|
98 | - $prefix = '…'; |
|
99 | - } |
|
93 | + if ($start <= 25) { |
|
94 | + $start = 0; |
|
95 | + $prefix = ''; |
|
96 | + } else { |
|
97 | + $start -= 25; |
|
98 | + $prefix = '…'; |
|
99 | + } |
|
100 | 100 | |
101 | - if ((mb_strlen($message) - $end) <= 25) { |
|
102 | - $end = mb_strlen($message); |
|
103 | - $suffix = ''; |
|
104 | - } else { |
|
105 | - $end += 25; |
|
106 | - $suffix = '…'; |
|
107 | - } |
|
101 | + if ((mb_strlen($message) - $end) <= 25) { |
|
102 | + $end = mb_strlen($message); |
|
103 | + $suffix = ''; |
|
104 | + } else { |
|
105 | + $end += 25; |
|
106 | + $suffix = '…'; |
|
107 | + } |
|
108 | 108 | |
109 | - return $prefix . mb_substr($message, $start, $end - $start) . $suffix; |
|
110 | - } |
|
109 | + return $prefix . mb_substr($message, $start, $end - $start) . $suffix; |
|
110 | + } |
|
111 | 111 | } |
@@ -20,55 +20,55 @@ |
||
20 | 20 | use function pathinfo; |
21 | 21 | |
22 | 22 | class CommentsSearchProvider implements IProvider { |
23 | - public function __construct( |
|
24 | - private IUserManager $userManager, |
|
25 | - private IL10N $l10n, |
|
26 | - private IURLGenerator $urlGenerator, |
|
27 | - private LegacyProvider $legacyProvider, |
|
28 | - ) { |
|
29 | - } |
|
23 | + public function __construct( |
|
24 | + private IUserManager $userManager, |
|
25 | + private IL10N $l10n, |
|
26 | + private IURLGenerator $urlGenerator, |
|
27 | + private LegacyProvider $legacyProvider, |
|
28 | + ) { |
|
29 | + } |
|
30 | 30 | |
31 | - public function getId(): string { |
|
32 | - return 'comments'; |
|
33 | - } |
|
31 | + public function getId(): string { |
|
32 | + return 'comments'; |
|
33 | + } |
|
34 | 34 | |
35 | - public function getName(): string { |
|
36 | - return $this->l10n->t('Comments'); |
|
37 | - } |
|
35 | + public function getName(): string { |
|
36 | + return $this->l10n->t('Comments'); |
|
37 | + } |
|
38 | 38 | |
39 | - public function getOrder(string $route, array $routeParameters): int { |
|
40 | - if ($route === 'files.View.index') { |
|
41 | - // Files first |
|
42 | - return 0; |
|
43 | - } |
|
44 | - return 10; |
|
45 | - } |
|
39 | + public function getOrder(string $route, array $routeParameters): int { |
|
40 | + if ($route === 'files.View.index') { |
|
41 | + // Files first |
|
42 | + return 0; |
|
43 | + } |
|
44 | + return 10; |
|
45 | + } |
|
46 | 46 | |
47 | - public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
48 | - return SearchResult::complete( |
|
49 | - $this->l10n->t('Comments'), |
|
50 | - array_map(function (Result $result) { |
|
51 | - $path = $result->path; |
|
52 | - $isUser = $this->userManager->userExists($result->authorId); |
|
53 | - $avatarUrl = $isUser |
|
54 | - ? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42]) |
|
55 | - : $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]); |
|
56 | - $link = $this->urlGenerator->linkToRoute( |
|
57 | - 'files.View.showFile', |
|
58 | - ['fileid' => $result->fileId] |
|
59 | - ); |
|
60 | - $searchResultEntry = new SearchResultEntry( |
|
61 | - $avatarUrl, |
|
62 | - $result->name, |
|
63 | - $path, |
|
64 | - $link, |
|
65 | - '', |
|
66 | - true |
|
67 | - ); |
|
68 | - $searchResultEntry->addAttribute('fileId', (string)$result->fileId); |
|
69 | - $searchResultEntry->addAttribute('path', $path); |
|
70 | - return $searchResultEntry; |
|
71 | - }, $this->legacyProvider->search($query->getTerm())) |
|
72 | - ); |
|
73 | - } |
|
47 | + public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
48 | + return SearchResult::complete( |
|
49 | + $this->l10n->t('Comments'), |
|
50 | + array_map(function (Result $result) { |
|
51 | + $path = $result->path; |
|
52 | + $isUser = $this->userManager->userExists($result->authorId); |
|
53 | + $avatarUrl = $isUser |
|
54 | + ? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42]) |
|
55 | + : $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]); |
|
56 | + $link = $this->urlGenerator->linkToRoute( |
|
57 | + 'files.View.showFile', |
|
58 | + ['fileid' => $result->fileId] |
|
59 | + ); |
|
60 | + $searchResultEntry = new SearchResultEntry( |
|
61 | + $avatarUrl, |
|
62 | + $result->name, |
|
63 | + $path, |
|
64 | + $link, |
|
65 | + '', |
|
66 | + true |
|
67 | + ); |
|
68 | + $searchResultEntry->addAttribute('fileId', (string)$result->fileId); |
|
69 | + $searchResultEntry->addAttribute('path', $path); |
|
70 | + return $searchResultEntry; |
|
71 | + }, $this->legacyProvider->search($query->getTerm())) |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | } |
@@ -21,79 +21,79 @@ |
||
21 | 21 | use function count; |
22 | 22 | |
23 | 23 | class LegacyProvider extends Provider { |
24 | - /** |
|
25 | - * Search for $query |
|
26 | - * |
|
27 | - * @param string $query |
|
28 | - * @return array An array of OCP\Search\Result's |
|
29 | - * @since 7.0.0 |
|
30 | - */ |
|
31 | - public function search($query): array { |
|
32 | - $cm = Server::get(ICommentsManager::class); |
|
33 | - $us = Server::get(IUserSession::class); |
|
34 | - |
|
35 | - $user = $us->getUser(); |
|
36 | - if (!$user instanceof IUser) { |
|
37 | - return []; |
|
38 | - } |
|
39 | - $uf = \OC::$server->getUserFolder($user->getUID()); |
|
40 | - |
|
41 | - if ($uf === null) { |
|
42 | - return []; |
|
43 | - } |
|
44 | - |
|
45 | - $result = []; |
|
46 | - $numComments = 50; |
|
47 | - $offset = 0; |
|
48 | - |
|
49 | - while (count($result) < $numComments) { |
|
50 | - /** @var IComment[] $comments */ |
|
51 | - $comments = $cm->search($query, 'files', '', 'comment', $offset, $numComments); |
|
52 | - |
|
53 | - foreach ($comments as $comment) { |
|
54 | - if ($comment->getActorType() !== 'users') { |
|
55 | - continue; |
|
56 | - } |
|
57 | - |
|
58 | - $displayName = $cm->resolveDisplayName('user', $comment->getActorId()); |
|
59 | - |
|
60 | - try { |
|
61 | - $file = $this->getFileForComment($uf, $comment); |
|
62 | - $result[] = new Result($query, |
|
63 | - $comment, |
|
64 | - $displayName, |
|
65 | - $file->getPath(), |
|
66 | - $file->getId(), |
|
67 | - ); |
|
68 | - } catch (NotFoundException|InvalidPathException $e) { |
|
69 | - continue; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if (count($comments) < $numComments) { |
|
74 | - // Didn't find more comments when we tried to get, so there are no more comments. |
|
75 | - return $result; |
|
76 | - } |
|
77 | - |
|
78 | - $offset += $numComments; |
|
79 | - $numComments = 50 - count($result); |
|
80 | - } |
|
81 | - |
|
82 | - return $result; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param Folder $userFolder |
|
87 | - * @param IComment $comment |
|
88 | - * @return Node |
|
89 | - * @throws NotFoundException |
|
90 | - */ |
|
91 | - protected function getFileForComment(Folder $userFolder, IComment $comment): Node { |
|
92 | - $nodes = $userFolder->getById((int)$comment->getObjectId()); |
|
93 | - if (empty($nodes)) { |
|
94 | - throw new NotFoundException('File not found'); |
|
95 | - } |
|
96 | - |
|
97 | - return array_shift($nodes); |
|
98 | - } |
|
24 | + /** |
|
25 | + * Search for $query |
|
26 | + * |
|
27 | + * @param string $query |
|
28 | + * @return array An array of OCP\Search\Result's |
|
29 | + * @since 7.0.0 |
|
30 | + */ |
|
31 | + public function search($query): array { |
|
32 | + $cm = Server::get(ICommentsManager::class); |
|
33 | + $us = Server::get(IUserSession::class); |
|
34 | + |
|
35 | + $user = $us->getUser(); |
|
36 | + if (!$user instanceof IUser) { |
|
37 | + return []; |
|
38 | + } |
|
39 | + $uf = \OC::$server->getUserFolder($user->getUID()); |
|
40 | + |
|
41 | + if ($uf === null) { |
|
42 | + return []; |
|
43 | + } |
|
44 | + |
|
45 | + $result = []; |
|
46 | + $numComments = 50; |
|
47 | + $offset = 0; |
|
48 | + |
|
49 | + while (count($result) < $numComments) { |
|
50 | + /** @var IComment[] $comments */ |
|
51 | + $comments = $cm->search($query, 'files', '', 'comment', $offset, $numComments); |
|
52 | + |
|
53 | + foreach ($comments as $comment) { |
|
54 | + if ($comment->getActorType() !== 'users') { |
|
55 | + continue; |
|
56 | + } |
|
57 | + |
|
58 | + $displayName = $cm->resolveDisplayName('user', $comment->getActorId()); |
|
59 | + |
|
60 | + try { |
|
61 | + $file = $this->getFileForComment($uf, $comment); |
|
62 | + $result[] = new Result($query, |
|
63 | + $comment, |
|
64 | + $displayName, |
|
65 | + $file->getPath(), |
|
66 | + $file->getId(), |
|
67 | + ); |
|
68 | + } catch (NotFoundException|InvalidPathException $e) { |
|
69 | + continue; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if (count($comments) < $numComments) { |
|
74 | + // Didn't find more comments when we tried to get, so there are no more comments. |
|
75 | + return $result; |
|
76 | + } |
|
77 | + |
|
78 | + $offset += $numComments; |
|
79 | + $numComments = 50 - count($result); |
|
80 | + } |
|
81 | + |
|
82 | + return $result; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param Folder $userFolder |
|
87 | + * @param IComment $comment |
|
88 | + * @return Node |
|
89 | + * @throws NotFoundException |
|
90 | + */ |
|
91 | + protected function getFileForComment(Folder $userFolder, IComment $comment): Node { |
|
92 | + $nodes = $userFolder->getById((int)$comment->getObjectId()); |
|
93 | + if (empty($nodes)) { |
|
94 | + throw new NotFoundException('File not found'); |
|
95 | + } |
|
96 | + |
|
97 | + return array_shift($nodes); |
|
98 | + } |
|
99 | 99 | } |