aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Comments/Comment.php37
-rw-r--r--lib/public/Comments/IComment.php22
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php
index f6f0801c683..b5f063be323 100644
--- a/lib/private/Comments/Comment.php
+++ b/lib/private/Comments/Comment.php
@@ -204,6 +204,43 @@ class Comment implements IComment {
}
/**
+ * returns an array containing mentions that are included in the comment
+ *
+ * @return array each mention provides a 'type' and an 'id', see example below
+ * @since 9.2.0
+ *
+ * The return array looks like:
+ * [
+ * [
+ * 'type' => 'user',
+ * 'id' => 'citizen4'
+ * ],
+ * [
+ * 'type' => 'group',
+ * 'id' => 'media'
+ * ],
+ * …
+ * ]
+ *
+ */
+ public function getMentions() {
+ $ok = preg_match_all('/\B@[a-z0-9_\-@\.\']+/i', $this->getMessage(), $mentions);
+ if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) {
+ return [];
+ }
+ $uids = array_unique($mentions[0]);
+ $result = [];
+ foreach ($uids as $uid) {
+ // exclude author, no self-mentioning
+ if($uid === '@' . $this->getActorId()) {
+ continue;
+ }
+ $result[] = ['type' => 'user', 'id' => substr($uid, 1)];
+ }
+ return $result;
+ }
+
+ /**
* returns the verb of the comment
*
* @return string
diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php
index bb997a07223..8210d4c8c7e 100644
--- a/lib/public/Comments/IComment.php
+++ b/lib/public/Comments/IComment.php
@@ -133,6 +133,28 @@ interface IComment {
public function setMessage($message);
/**
+ * returns an array containing mentions that are included in the comment
+ *
+ * @return array each mention provides a 'type' and an 'id', see example below
+ * @since 9.2.0
+ *
+ * The return array looks like:
+ * [
+ * [
+ * 'type' => 'user',
+ * 'id' => 'citizen4'
+ * ],
+ * [
+ * 'type' => 'group',
+ * 'id' => 'media'
+ * ],
+ * …
+ * ]
+ *
+ */
+ public function getMentions();
+
+ /**
* returns the verb of the comment
*
* @return string