Skip to content

Commit

Permalink
Fix the comments UI and activities for space-mentions
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 15, 2018
1 parent 650c53f commit cd65fa1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
20 changes: 16 additions & 4 deletions apps/comments/js/commentstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,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;
Expand Down Expand Up @@ -598,9 +605,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()));
Expand Down
7 changes: 6 additions & 1 deletion apps/comments/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,13 @@ protected function parseMessage(IEvent $event) {
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
Expand Down

0 comments on commit cd65fa1

Please sign in to comment.