aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2016-10-14 00:19:31 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2016-10-19 00:33:55 +0200
commitfea3e20a805de12546312c68557ddbd8498b9414 (patch)
tree4cc3f481c51f3feab18c29164a57acbe70d86f5f /apps/dav
parente115bf96e742909b78150d04305b67196b94115c (diff)
downloadnextcloud-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 'apps/dav')
-rw-r--r--apps/dav/lib/Comments/CommentNode.php33
-rw-r--r--apps/dav/tests/unit/Comments/CommentsNodeTest.php15
2 files changed, 47 insertions, 1 deletions
diff --git a/apps/dav/lib/Comments/CommentNode.php b/apps/dav/lib/Comments/CommentNode.php
index f247921be79..2f4490ac08a 100644
--- a/apps/dav/lib/Comments/CommentNode.php
+++ b/apps/dav/lib/Comments/CommentNode.php
@@ -41,6 +41,10 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread';
const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message';
const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName';
+ const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions';
+ const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention';
+ const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType';
+ const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId';
/** @var IComment */
public $comment;
@@ -85,6 +89,9 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
return strpos($name, 'get') === 0;
});
foreach($methods as $getter) {
+ if($getter === 'getMentions') {
+ continue; // special treatment
+ }
$name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3));
$this->properties[$name] = $getter;
}
@@ -113,7 +120,11 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
// re-used property names are defined as constants
self::PROPERTY_NAME_MESSAGE,
self::PROPERTY_NAME_ACTOR_DISPLAYNAME,
- self::PROPERTY_NAME_UNREAD
+ self::PROPERTY_NAME_UNREAD,
+ self::PROPERTY_NAME_MENTIONS,
+ self::PROPERTY_NAME_MENTION,
+ self::PROPERTY_NAME_MENTION_TYPE,
+ self::PROPERTY_NAME_MENTION_ID,
];
}
@@ -240,6 +251,8 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
$result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName;
}
+ $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue();
+
$unread = null;
$user = $this->userSession->getUser();
if(!is_null($user)) {
@@ -260,4 +273,22 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
return $result;
}
+
+ /**
+ * transforms a mentions array as returned from IComment->getMentions to an
+ * array with DAV-compatible structure that can be assigned to the
+ * PROPERTY_NAME_MENTION property.
+ *
+ * @return array
+ */
+ protected function composeMentionsPropertyValue() {
+ return array_map(function($mention) {
+ return [
+ self::PROPERTY_NAME_MENTION => [
+ self::PROPERTY_NAME_MENTION_TYPE => $mention['type'],
+ self::PROPERTY_NAME_MENTION_ID => $mention['id'],
+ ]
+ ];
+ }, $this->comment->getMentions());
+ }
}
diff --git a/apps/dav/tests/unit/Comments/CommentsNodeTest.php b/apps/dav/tests/unit/Comments/CommentsNodeTest.php
index 1c7bd782496..d5a60051452 100644
--- a/apps/dav/tests/unit/Comments/CommentsNodeTest.php
+++ b/apps/dav/tests/unit/Comments/CommentsNodeTest.php
@@ -373,6 +373,10 @@ class CommentsNodeTest extends \Test\TestCase {
$ns . 'topmostParentId' => '2',
$ns . 'childrenCount' => 3,
$ns . 'message' => 'such a nice file you haveā€¦',
+ $ns . 'mentions' => [
+ [ $ns . 'mention' => [ $ns . 'mentionType' => 'user', $ns . 'mentionId' => 'alice'] ],
+ [ $ns . 'mention' => [ $ns . 'mentionType' => 'user', $ns . 'mentionId' => 'bob'] ],
+ ],
$ns . 'verb' => 'comment',
$ns . 'actorType' => 'users',
$ns . 'actorId' => 'alice',
@@ -405,6 +409,13 @@ class CommentsNodeTest extends \Test\TestCase {
->will($this->returnValue($expected[$ns . 'message']));
$this->comment->expects($this->once())
+ ->method('getMentions')
+ ->willReturn([
+ ['type' => 'user', 'id' => 'alice'],
+ ['type' => 'user', 'id' => 'bob'],
+ ]);
+
+ $this->comment->expects($this->once())
->method('getVerb')
->will($this->returnValue($expected[$ns . 'verb']));
@@ -475,6 +486,10 @@ class CommentsNodeTest extends \Test\TestCase {
->method('getCreationDateTime')
->will($this->returnValue($creationDT));
+ $this->comment->expects($this->any())
+ ->method('getMentions')
+ ->willReturn([]);
+
$this->commentsManager->expects($this->once())
->method('getReadMark')
->will($this->returnValue($readDT));