summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-07 16:27:36 +0100
committerGitHub <noreply@github.com>2018-11-07 16:27:36 +0100
commitab3543380c96b0beb5de4db977bbc12894379288 (patch)
tree422cbaa88830034d9406ecf2eac44db00548c59d /apps
parent11f8dcb59caf336536fb908510e2955a5ae0eae8 (diff)
parent375589b274ad6da55f1a516c953b807105dfd2a4 (diff)
downloadnextcloud-server-ab3543380c96b0beb5de4db977bbc12894379288.tar.gz
nextcloud-server-ab3543380c96b0beb5de4db977bbc12894379288.zip
Merge pull request #11836 from nextcloud/bugfix/2443/comment-mentions-with-spaces
Comment mentions with spaces
Diffstat (limited to 'apps')
-rw-r--r--apps/comments/js/commentstabview.js20
-rw-r--r--apps/comments/lib/Activity/Provider.php7
2 files changed, 22 insertions, 5 deletions
diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js
index 8ea4dbc2ff2..04b0f292299 100644
--- a/apps/comments/js/commentstabview.js
+++ b/apps/comments/js/commentstabview.js
@@ -416,15 +416,22 @@
return;
}
var mention = '@' + mentions[i].mentionId;
+ if (mentions[i].mentionId.indexOf(' ') !== -1) {
+ mention = _.escape('@"' + mentions[i].mentionId + '"');
+ }
// escape possible regex characters in the name
mention = mention.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+ var regex = new RegExp("(^|\\s)(" + mention + ")\\b", 'g');
+ if (mentions[i].mentionId.indexOf(' ') !== -1) {
+ regex = new RegExp("(^|\\s)(" + mention + ")", 'g');
+ }
var displayName = this._composeHTMLMention(mentions[i].mentionId, mentions[i].mentionDisplayName);
// replace every mention either at the start of the input or after a whitespace
// followed by a non-word character.
- message = message.replace(new RegExp("(^|\\s)(" + mention + ")\\b", 'g'),
+ message = message.replace(regex,
function(match, p1) {
// to get number of whitespaces (0 vs 1) right
return p1+displayName;
@@ -602,9 +609,14 @@
var $comment = $el.clone();
$comment.find('.avatar-name-wrapper').each(function () {
- var $this = $(this);
- var $inserted = $this.parent();
- $inserted.html('@' + $this.find('.avatar').data('username'));
+ var $this = $(this),
+ $inserted = $this.parent(),
+ userId = $this.find('.avatar').data('username');
+ if (userId.indexOf(' ') !== -1) {
+ $inserted.html('@"' + userId + '"');
+ } else {
+ $inserted.html('@' + userId);
+ }
});
$comment.html(OCP.Comments.richToPlain($comment.html()));
diff --git a/apps/comments/lib/Activity/Provider.php b/apps/comments/lib/Activity/Provider.php
index c21b7a9c4fd..4940bb6afec 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