Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/comments/lib/Activity/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Util;

/**
* Class Extension
Expand Down Expand Up @@ -306,6 +307,25 @@ protected function convertParameterToComment($parameter) {
$comment = $this->commentsManager->get((int) $matches[1]);
$message = $comment->getMessage();
$message = str_replace("\n", '<br />', str_replace(['<', '>'], ['&lt;', '&gt;'], $message));

foreach ($comment->getMentions() as $mention) {
if ($mention['type'] !== 'user') {
continue;
}

try {
$displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);
} catch (\OutOfBoundsException $e) {
// No displayname, upon client's discretion what to display.
$displayName = $mention['id'];
}

$message = preg_replace(
'/(^|\s)(' . '@' . $mention['id'] . ')(\b)/',
'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}',
$message
);
}
return $message;
} catch (NotFoundException $e) {
return '';
Expand All @@ -314,4 +334,9 @@ protected function convertParameterToComment($parameter) {

return '';
}

protected function regexSafeUser($uid, $displayName) {
// FIXME evil internal API hackery, do NOT copy this
return str_replace('$', '\$', '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($uid) . '</user>');
}
}