From 3784fa2074ba411860e2986b7b324f4c93ca899e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 17 Jan 2018 13:48:43 +0100 Subject: [PATCH 1/3] comments should compile mentions also if done by author it is used by clients for formatting reasons, there is no reason not format the author if her handle is included in the comment body. It is unrelated to sending out notifications. Signed-off-by: Arthur Schiwon --- lib/private/Comments/Comment.php | 4 ---- tests/lib/Comments/CommentTest.php | 9 +++++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index acfebd32028..dd790c2e50a 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -232,10 +232,6 @@ class Comment implements IComment { $uids = array_unique($mentions[0]); $result = []; foreach ($uids as $uid) { - // exclude author, no self-mentioning - if($uid === '@' . $this->getActorId()) { - continue; - } $result[] = ['type' => 'user', 'id' => substr($uid, 1)]; } return $result; diff --git a/tests/lib/Comments/CommentTest.php b/tests/lib/Comments/CommentTest.php index 10ec4bae7d5..6f67356ccae 100644 --- a/tests/lib/Comments/CommentTest.php +++ b/tests/lib/Comments/CommentTest.php @@ -8,6 +8,9 @@ use Test\TestCase; class CommentTest extends TestCase { + /** + * @throws \OCP\Comments\IllegalIDChangeException + */ public function testSettersValidInput() { $comment = new Comment(); @@ -58,6 +61,9 @@ class CommentTest extends TestCase { $comment->setId('c17'); } + /** + * @throws \OCP\Comments\IllegalIDChangeException + */ public function testResetId() { $comment = new Comment(); $comment->setId('c23'); @@ -133,7 +139,7 @@ class CommentTest extends TestCase { '@alice @bob look look, a duplication @alice test @bob!', ['alice', 'bob'] ], [ - '@alice is the author, but notify @bob!', ['bob'], 'alice' + '@alice is the author, notify @bob, nevertheless mention her!', ['alice', 'bob'], 'alice' ], [ '@foobar and @barfoo you should know, @foo@bar.com is valid' . @@ -159,7 +165,6 @@ class CommentTest extends TestCase { $uid = array_shift($expectedUids); $this->assertSame('user', $mention['type']); $this->assertSame($uid, $mention['id']); - $this->assertNotSame($author, $mention['id']); } $this->assertEmpty($mentions); $this->assertEmpty($expectedUids); From 6fdd6861118f55a9e740552b82382f55e9415eea Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 17 Jan 2018 13:49:18 +0100 Subject: [PATCH 2/3] do not offer the handle of the current user for auto completion Signed-off-by: Arthur Schiwon --- .../Collaboration/Collaborators/Search.php | 9 ++++ .../Collaborators/UserPlugin.php | 11 +++++ .../Collaborators/UserPluginTest.php | 47 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index e9b15dd1201..0e856eeb6f1 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -40,6 +40,15 @@ class Search implements ISearch { $this->c = $c; } + /** + * @param $search + * @param array $shareTypes + * @param $lookup + * @param $limit + * @param $offset + * @return array + * @throws \OCP\AppFramework\QueryException + */ public function search($search, array $shareTypes, $lookup, $limit, $offset) { $hasMoreResults = false; diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php index 86a55aa428f..ad677703547 100644 --- a/lib/private/Collaboration/Collaborators/UserPlugin.php +++ b/lib/private/Collaboration/Collaborators/UserPlugin.php @@ -83,6 +83,8 @@ class UserPlugin implements ISearchPlugin { } } + $this->takeOutCurrentUser($users); + if (!$this->shareeEnumeration || sizeof($users) < $limit) { $hasMoreResults = true; } @@ -146,4 +148,13 @@ class UserPlugin implements ISearchPlugin { return $hasMoreResults; } + + public function takeOutCurrentUser(array &$users) { + $currentUser = $this->userSession->getUser(); + if(!is_null($currentUser)) { + if (isset($users[$currentUser->getUID()])) { + unset($users[$currentUser->getUID()]); + } + } + } } diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index 7d6d9c645a0..cfb97de8676 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -442,4 +442,51 @@ class UserPluginTest extends TestCase { $this->assertEquals($expected, $result['users']); $this->assertSame($reachedEnd, $moreResults); } + + public function takeOutCurrentUserProvider() { + $inputUsers = [ + 'alice' => 'Alice', + 'bob' => 'Bob', + 'carol' => 'Carol' + ]; + return [ + [ + $inputUsers, + ['alice', 'carol'], + 'bob' + ], + [ + $inputUsers, + ['alice', 'bob', 'carol'], + 'dave' + ], + [ + $inputUsers, + ['alice', 'bob', 'carol'], + null + ] + ]; + } + + /** + * @dataProvider takeOutCurrentUserProvider + * @param array $users + * @param array $expectedUIDs + * @param $currentUserId + */ + public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId) { + $this->instantiatePlugin(); + + $this->session->expects($this->once()) + ->method('getUser') + ->willReturnCallback(function() use ($currentUserId) { + if($currentUserId !== null) { + return $this->getUserMock($currentUserId, $currentUserId); + } + return null; + }); + + $this->plugin->takeOutCurrentUser($users); + $this->assertSame($expectedUIDs, array_keys($users)); + } } From 39f34603f20103a5fc44425175bf271e3fc91207 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 17 Jan 2018 13:58:42 +0100 Subject: [PATCH 3/3] add types to php doc Signed-off-by: Arthur Schiwon --- lib/private/Collaboration/Collaborators/Search.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index 0e856eeb6f1..bb1bd6d1711 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -41,11 +41,11 @@ class Search implements ISearch { } /** - * @param $search + * @param string $search * @param array $shareTypes - * @param $lookup - * @param $limit - * @param $offset + * @param bool $lookup + * @param int|null $limit + * @param int|null $offset * @return array * @throws \OCP\AppFramework\QueryException */