Skip to content

Commit 92bc33d

Browse files
committed
Backport of format self-mentions, but don't offer them #7914
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 <blizzz@arthur-schiwon.de> do not offer the handle of the current user for auto completion Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de> add types to php doc Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 266c640 commit 92bc33d

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

lib/private/Collaboration/Collaborators/Search.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public function __construct(IContainer $c) {
4040
$this->c = $c;
4141
}
4242

43+
/**
44+
* @param string $search
45+
* @param array $shareTypes
46+
* @param bool $lookup
47+
* @param int|null $limit
48+
* @param int|null $offset
49+
* @return array
50+
* @throws \OCP\AppFramework\QueryException
51+
*/
4352
public function search($search, array $shareTypes, $lookup, $limit, $offset) {
4453
$hasMoreResults = false;
4554

lib/private/Collaboration/Collaborators/UserPlugin.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
8383
}
8484
}
8585

86+
$this->takeOutCurrentUser($users);
87+
8688
if (!$this->shareeEnumeration || sizeof($users) < $limit) {
8789
$hasMoreResults = true;
8890
}
@@ -146,4 +148,13 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
146148

147149
return $hasMoreResults;
148150
}
151+
152+
public function takeOutCurrentUser(array &$users) {
153+
$currentUser = $this->userSession->getUser();
154+
if(!is_null($currentUser)) {
155+
if (isset($users[$currentUser->getUID()])) {
156+
unset($users[$currentUser->getUID()]);
157+
}
158+
}
159+
}
149160
}

lib/private/Comments/Comment.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ public function getMentions() {
232232
$uids = array_unique($mentions[0]);
233233
$result = [];
234234
foreach ($uids as $uid) {
235-
// exclude author, no self-mentioning
236-
if($uid === '@' . $this->getActorId()) {
237-
continue;
238-
}
239235
$result[] = ['type' => 'user', 'id' => substr($uid, 1)];
240236
}
241237
return $result;

tests/lib/Collaboration/Collaborators/UserPluginTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,51 @@ function($appName, $key, $default)
442442
$this->assertEquals($expected, $result['users']);
443443
$this->assertSame($reachedEnd, $moreResults);
444444
}
445+
446+
public function takeOutCurrentUserProvider() {
447+
$inputUsers = [
448+
'alice' => 'Alice',
449+
'bob' => 'Bob',
450+
'carol' => 'Carol'
451+
];
452+
return [
453+
[
454+
$inputUsers,
455+
['alice', 'carol'],
456+
'bob'
457+
],
458+
[
459+
$inputUsers,
460+
['alice', 'bob', 'carol'],
461+
'dave'
462+
],
463+
[
464+
$inputUsers,
465+
['alice', 'bob', 'carol'],
466+
null
467+
]
468+
];
469+
}
470+
471+
/**
472+
* @dataProvider takeOutCurrentUserProvider
473+
* @param array $users
474+
* @param array $expectedUIDs
475+
* @param $currentUserId
476+
*/
477+
public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId) {
478+
$this->instantiatePlugin();
479+
480+
$this->session->expects($this->once())
481+
->method('getUser')
482+
->willReturnCallback(function() use ($currentUserId) {
483+
if($currentUserId !== null) {
484+
return $this->getUserMock($currentUserId, $currentUserId);
485+
}
486+
return null;
487+
});
488+
489+
$this->plugin->takeOutCurrentUser($users);
490+
$this->assertSame($expectedUIDs, array_keys($users));
491+
}
445492
}

tests/lib/Comments/CommentTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
class CommentTest extends TestCase {
1010

11+
/**
12+
* @throws \OCP\Comments\IllegalIDChangeException
13+
*/
1114
public function testSettersValidInput() {
1215
$comment = new Comment();
1316

@@ -58,6 +61,9 @@ public function testSetIdIllegalInput() {
5861
$comment->setId('c17');
5962
}
6063

64+
/**
65+
* @throws \OCP\Comments\IllegalIDChangeException
66+
*/
6167
public function testResetId() {
6268
$comment = new Comment();
6369
$comment->setId('c23');
@@ -133,7 +139,7 @@ public function mentionsProvider() {
133139
'@alice @bob look look, a duplication @alice test @bob!', ['alice', 'bob']
134140
],
135141
[
136-
'@alice is the author, but notify @bob!', ['bob'], 'alice'
142+
'@alice is the author, notify @bob, nevertheless mention her!', ['alice', 'bob'], 'alice'
137143
],
138144
[
139145
'@foobar and @barfoo you should know, @foo@bar.com is valid' .
@@ -159,7 +165,6 @@ public function testMentions($message, $expectedUids, $author = null) {
159165
$uid = array_shift($expectedUids);
160166
$this->assertSame('user', $mention['type']);
161167
$this->assertSame($uid, $mention['id']);
162-
$this->assertNotSame($author, $mention['id']);
163168
}
164169
$this->assertEmpty($mentions);
165170
$this->assertEmpty($expectedUids);

0 commit comments

Comments
 (0)