aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/comments/js/commentstabview.js2
-rw-r--r--apps/comments/lib/Collaboration/CommentersSorter.php15
-rw-r--r--apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php23
3 files changed, 32 insertions, 8 deletions
diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js
index 7b5a25b7e8e..4d67ca90825 100644
--- a/apps/comments/js/commentstabview.js
+++ b/apps/comments/js/commentstabview.js
@@ -238,7 +238,7 @@
search: query,
itemType: 'files',
itemId: s.model.get('id'),
- sorter: 'comments|share-recipients',
+ sorter: 'commenters|share-recipients',
limit: OC.appConfig.comments.maxAutoCompleteResults
},
function (data) {
diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php
index 8a24592c30b..b8bb745b3b8 100644
--- a/apps/comments/lib/Collaboration/CommentersSorter.php
+++ b/apps/comments/lib/Collaboration/CommentersSorter.php
@@ -84,12 +84,23 @@ class CommentersSorter implements ISorter {
* @return array
*/
protected function retrieveCommentsInformation($type, $id) {
- $comments = $this->commentsManager->getForObject($type, $id, 1);
+ $comments = $this->commentsManager->getForObject($type, $id);
if(count($comments) === 0) {
return [];
}
- return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId());
+ $actors = [];
+ foreach ($comments as $comment) {
+ if(!isset($actors[$comment->getActorType()])) {
+ $actors[$comment->getActorType()] = [];
+ }
+ if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
+ $actors[$comment->getActorType()][$comment->getActorId()] = 1;
+ } else {
+ $actors[$comment->getActorType()][$comment->getActorId()]++;
+ }
+ }
+ return $actors;
}
protected function compare(array $a, array $b, array $commenters) {
diff --git a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
index 95a74f118c0..0cc3e3d4b61 100644
--- a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
+++ b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
@@ -27,6 +27,7 @@ namespace OCA\Comments\Tests\Unit\Collaboration;
use OCA\Comments\Collaboration\CommentersSorter;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
+use OCP\IConfig;
use Test\TestCase;
class CommentersSorterTest extends TestCase {
@@ -48,13 +49,25 @@ class CommentersSorterTest extends TestCase {
* @param $data
*/
public function testSort($data) {
- $this->commentsManager->expects($this->once())
- ->method('getForObject')
- ->willReturn([$this->createMock(IComment::class)]);
+ $commentMocks = [];
+ foreach($data['actors'] as $actorType => $actors) {
+ foreach ($actors as $actorId => $noOfComments) {
+ for($i=0;$i<$noOfComments;$i++) {
+ $mock = $this->createMock(IComment::class);
+ $mock->expects($this->atLeastOnce())
+ ->method('getActorType')
+ ->willReturn($actorType);
+ $mock->expects($this->atLeastOnce())
+ ->method('getActorId')
+ ->willReturn($actorId);
+ $commentMocks[] = $mock;
+ }
+ }
+ }
$this->commentsManager->expects($this->once())
- ->method('getActorsInTree')
- ->willReturn($data['actors']);
+ ->method('getForObject')
+ ->willReturn($commentMocks);
$workArray = $data['input'];
$this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']);