Skip to content

Commit

Permalink
Fix comment mentions in activities
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 26, 2016
1 parent b98dfac commit 7c7ca1d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 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 @@ -304,8 +305,25 @@ protected function convertParameterToComment($parameter) {
if (preg_match('/^\<parameter\>(\d*)\<\/parameter\>$/', $parameter, $matches)) {
try {
$comment = $this->commentsManager->get((int) $matches[1]);
$users = [];
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 = '<user> ' . $mention['id'];
}

// FIXME evil internal API hackery, do NOT copy this
$users['@' . $mention['id']] = '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($mention['id']) . '</user>';
}
$message = $comment->getMessage();
$message = str_replace("\n", '<br />', str_replace(['<', '>'], ['&lt;', '&gt;'], $message));
$message = str_replace(array_keys($users), array_values($users), $message);
return $message;
} catch (NotFoundException $e) {
return '';
Expand Down

0 comments on commit 7c7ca1d

Please sign in to comment.