diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-10-14 00:19:31 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-10-19 00:33:55 +0200 |
commit | fea3e20a805de12546312c68557ddbd8498b9414 (patch) | |
tree | 4cc3f481c51f3feab18c29164a57acbe70d86f5f /lib | |
parent | e115bf96e742909b78150d04305b67196b94115c (diff) | |
download | nextcloud-server-fea3e20a805de12546312c68557ddbd8498b9414.tar.gz nextcloud-server-fea3e20a805de12546312c68557ddbd8498b9414.zip |
move mention extraction to (I)Comment and report mentions via DAV
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Comments/Comment.php | 37 | ||||
-rw-r--r-- | lib/public/Comments/IComment.php | 22 |
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 |