Fix the comments UI and activities for space-mentions

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-10-12 14:26:22 +02:00
parent 10ba0bed8a
commit 375589b274
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 22 additions and 5 deletions

View File

@ -416,15 +416,22 @@
return; return;
} }
var mention = '@' + mentions[i].mentionId; var mention = '@' + mentions[i].mentionId;
if (mentions[i].mentionId.indexOf(' ') !== -1) {
mention = _.escape('@"' + mentions[i].mentionId + '"');
}
// escape possible regex characters in the name // escape possible regex characters in the name
mention = mention.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); 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); var displayName = this._composeHTMLMention(mentions[i].mentionId, mentions[i].mentionDisplayName);
// replace every mention either at the start of the input or after a whitespace // replace every mention either at the start of the input or after a whitespace
// followed by a non-word character. // followed by a non-word character.
message = message.replace(new RegExp("(^|\\s)(" + mention + ")\\b", 'g'), message = message.replace(regex,
function(match, p1) { function(match, p1) {
// to get number of whitespaces (0 vs 1) right // to get number of whitespaces (0 vs 1) right
return p1+displayName; return p1+displayName;
@ -602,9 +609,14 @@
var $comment = $el.clone(); var $comment = $el.clone();
$comment.find('.avatar-name-wrapper').each(function () { $comment.find('.avatar-name-wrapper').each(function () {
var $this = $(this); var $this = $(this),
var $inserted = $this.parent(); $inserted = $this.parent(),
$inserted.html('@' + $this.find('.avatar').data('username')); userId = $this.find('.avatar').data('username');
if (userId.indexOf(' ') !== -1) {
$inserted.html('@"' + userId + '"');
} else {
$inserted.html('@' + userId);
}
}); });
$comment.html(OCP.Comments.richToPlain($comment.html())); $comment.html(OCP.Comments.richToPlain($comment.html()));

View File

@ -213,8 +213,13 @@ class Provider implements IProvider {
continue; continue;
} }
$pattern = '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/';
if (strpos($mention['id'], ' ') !== false) {
$pattern = '/(^|\s)(' . '@"' . $mention['id'] . '"' . ')(\b)?/';
}
$message = preg_replace( $message = preg_replace(
'/(^|\s)(' . '@' . $mention['id'] . ')(\b)/', $pattern,
//'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}', //'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}',
'${1}' . '{mention' . $mentionCount . '}' . '${3}', '${1}' . '{mention' . $mentionCount . '}' . '${3}',
$message $message