From 10ba0bed8a6a3f43526c36768feea522325d4a80 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Oct 2018 14:25:46 +0200 Subject: [PATCH 1/2] Match mentions when the username is wrapped in quotes Signed-off-by: Joas Schilling --- lib/private/Comments/Comment.php | 4 ++-- tests/lib/Comments/CommentTest.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 94c43be622..76c6e1d1f6 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -225,14 +225,14 @@ class Comment implements IComment { * */ public function getMentions() { - $ok = preg_match_all("/\B(?getMessage(), $mentions); + $ok = preg_match_all("/\B(?getMessage(), $mentions); if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { return []; } $uids = array_unique($mentions[0]); $result = []; foreach ($uids as $uid) { - $result[] = ['type' => 'user', 'id' => substr($uid, 1)]; + $result[] = ['type' => 'user', 'id' => trim(substr($uid, 1), '"')]; } return $result; } diff --git a/tests/lib/Comments/CommentTest.php b/tests/lib/Comments/CommentTest.php index 15dd9120e4..5fb19396d8 100644 --- a/tests/lib/Comments/CommentTest.php +++ b/tests/lib/Comments/CommentTest.php @@ -150,8 +150,11 @@ class CommentTest extends TestCase { ['foobar', 'barfoo', 'foo@bar.com', 'bar@foo.org@foobar.io', '23452-4333-54353-2342', 'yolo'] ], [ - '@@chef is also a valid mention, no matter how strange it looks', ['@chef'] - ] + '@@chef is also a valid mention, no matter how strange it looks', ['@chef'] + ], + [ + 'Also @"user with spaces" are now supported', ['user with spaces'] + ], ]; } From 375589b274ad6da55f1a516c953b807105dfd2a4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Oct 2018 14:26:22 +0200 Subject: [PATCH 2/2] Fix the comments UI and activities for space-mentions Signed-off-by: Joas Schilling --- apps/comments/js/commentstabview.js | Bin 21894 -> 22273 bytes apps/comments/lib/Activity/Provider.php | 7 ++++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js index 8ea4dbc2ff2ebed2d7314e9e4d07d695ac2eccd6..04b0f292299c808d78a5ccc2f98ddf7fffc88678 100644 GIT binary patch delta 426 zcmZo$&Dgk(al>PSdQKq7OjFRvP0cIG%+D*1&WzQAvOQDuGV@YWEBwlV2I+ z2!Kp0ODs|-N=;9#0Gc;B%1F-zqL4hNAsM8?r=+8xo({KobEqLJBP&?J<_@Dm5j`D< zZ&Wh#ic^b9Qd5BTtCVD97V8xx76HRVLldf?6e#VPGWnsN#AIK0L8w1K&Vxwc464cU j?xITIV1Xz^4F`qPoZ?hahys;K@PS$rtvBEHP~!st DbIl>b diff --git a/apps/comments/lib/Activity/Provider.php b/apps/comments/lib/Activity/Provider.php index c21b7a9c4f..4940bb6afe 100644 --- a/apps/comments/lib/Activity/Provider.php +++ b/apps/comments/lib/Activity/Provider.php @@ -213,8 +213,13 @@ class Provider implements IProvider { continue; } + $pattern = '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/'; + if (strpos($mention['id'], ' ') !== false) { + $pattern = '/(^|\s)(' . '@"' . $mention['id'] . '"' . ')(\b)?/'; + } + $message = preg_replace( - '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/', + $pattern, //'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}', '${1}' . '{mention' . $mentionCount . '}' . '${3}', $message