Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public function __construct(IContainer $c) {
$this->c = $c;
}

/**
* @param $search
* @param array $shareTypes
* @param $lookup
* @param $limit
* @param $offset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah stupid IDE ;)

* @return array
* @throws \OCP\AppFramework\QueryException
*/
public function search($search, array $shareTypes, $lookup, $limit, $offset) {
$hasMoreResults = false;

Expand Down
11 changes: 11 additions & 0 deletions lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
}

$this->takeOutCurrentUser($users);

if (!$this->shareeEnumeration || sizeof($users) < $limit) {
$hasMoreResults = true;
}
Expand Down Expand Up @@ -146,4 +148,13 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {

return $hasMoreResults;
}

public function takeOutCurrentUser(array &$users) {
$currentUser = $this->userSession->getUser();
if(!is_null($currentUser)) {
if (isset($users[$currentUser->getUID()])) {
unset($users[$currentUser->getUID()]);
}
}
}
}
4 changes: 0 additions & 4 deletions lib/private/Comments/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ public function getMentions() {
$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;
Expand Down
47 changes: 47 additions & 0 deletions tests/lib/Collaboration/Collaborators/UserPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,51 @@ function($appName, $key, $default)
$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));
}
}
9 changes: 7 additions & 2 deletions tests/lib/Comments/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class CommentTest extends TestCase {

/**
* @throws \OCP\Comments\IllegalIDChangeException
*/
public function testSettersValidInput() {
$comment = new Comment();

Expand Down Expand Up @@ -58,6 +61,9 @@ public function testSetIdIllegalInput() {
$comment->setId('c17');
}

/**
* @throws \OCP\Comments\IllegalIDChangeException
*/
public function testResetId() {
$comment = new Comment();
$comment->setId('c23');
Expand Down Expand Up @@ -133,7 +139,7 @@ public function mentionsProvider() {
'@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, @[email protected] is valid' .
Expand All @@ -159,7 +165,6 @@ public function testMentions($message, $expectedUids, $author = null) {
$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);
Expand Down