diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-10-28 22:47:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-28 22:47:15 +0200 |
commit | 48ce0ef19cdc244a7925b14ed0cb98804156dea3 (patch) | |
tree | 95f3580d180646c7152278335743feb13bfc6f2e | |
parent | f2cae3cee127220a5fde2726af8074837ee81ed1 (diff) | |
parent | 286482656bd77b9a162c4ab291508c5fed78b8da (diff) | |
download | nextcloud-server-48ce0ef19cdc244a7925b14ed0cb98804156dea3.tar.gz nextcloud-server-48ce0ef19cdc244a7925b14ed0cb98804156dea3.zip |
Merge pull request #1926 from nextcloud/fix-comment-mentions-in-activities
Fix comment mentions in activities
-rw-r--r-- | apps/comments/lib/Activity/Extension.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/apps/comments/lib/Activity/Extension.php b/apps/comments/lib/Activity/Extension.php index 6bf7bc9ac0b..2a155dd0064 100644 --- a/apps/comments/lib/Activity/Extension.php +++ b/apps/comments/lib/Activity/Extension.php @@ -29,6 +29,7 @@ use OCP\Comments\NotFoundException; use OCP\IL10N; use OCP\IURLGenerator; use OCP\L10N\IFactory; +use OCP\Util; /** * Class Extension @@ -306,6 +307,25 @@ class Extension implements IExtension { $comment = $this->commentsManager->get((int) $matches[1]); $message = $comment->getMessage(); $message = str_replace("\n", '<br />', str_replace(['<', '>'], ['<', '>'], $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 ''; @@ -314,4 +334,9 @@ class Extension implements IExtension { 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>'); + } } |