Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-10-28 23:47:15 +0300
committerGitHub <noreply@github.com>2016-10-28 23:47:15 +0300
commit48ce0ef19cdc244a7925b14ed0cb98804156dea3 (patch)
tree95f3580d180646c7152278335743feb13bfc6f2e
parentf2cae3cee127220a5fde2726af8074837ee81ed1 (diff)
parent286482656bd77b9a162c4ab291508c5fed78b8da (diff)
Merge pull request #1926 from nextcloud/fix-comment-mentions-in-activities
Fix comment mentions in activities
-rw-r--r--apps/comments/lib/Activity/Extension.php25
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(['<', '>'], ['&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 '';
@@ -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>');
+ }
}