From 79ab7703bab1798edd014c28cdbae8ada1060ee2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 26 Oct 2016 17:34:03 +0200 Subject: [PATCH] Fix comment mentions in activities Signed-off-by: Joas Schilling --- apps/comments/lib/Activity/Extension.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/comments/lib/Activity/Extension.php b/apps/comments/lib/Activity/Extension.php index 6bf7bc9ac0b78..0c0787dbee126 100644 --- a/apps/comments/lib/Activity/Extension.php +++ b/apps/comments/lib/Activity/Extension.php @@ -29,6 +29,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\L10N\IFactory; +use OCP\Util; /** * Class Extension @@ -304,8 +305,25 @@ protected function convertParameterToComment($parameter) { if (preg_match('/^\(\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 = $mention['id']; + } + + // FIXME evil internal API hackery, do NOT copy this + $users['@' . $mention['id']] = '' . Util::sanitizeHTML($mention['id']) . ''; + } $message = $comment->getMessage(); $message = str_replace("\n", '
', str_replace(['<', '>'], ['<', '>'], $message)); + $message = str_replace(array_keys($users), array_values($users), $message); return $message; } catch (NotFoundException $e) { return '';