]> source.dussan.org Git - nextcloud-server.git/commitdiff
set read marker via proppatch against entity
authorArthur Schiwon <blizzz@owncloud.com>
Mon, 1 Feb 2016 16:26:42 +0000 (17:26 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Mon, 1 Feb 2016 16:43:13 +0000 (17:43 +0100)
apps/dav/lib/comments/entitycollection.php
apps/dav/tests/unit/comments/entitycollection.php
apps/dav/tests/unit/comments/entitytypecollection.php

index 0cc5526c5297065e386f01a48a14c186422e81b1..a55a18c00c029260672d927c0763985d72fa0bcc 100644 (file)
@@ -25,7 +25,9 @@ use OCP\Comments\ICommentsManager;
 use OCP\Files\Folder;
 use OCP\ILogger;
 use OCP\IUserManager;
+use OCP\IUserSession;
 use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\PropPatch;
 
 /**
  * Class EntityCollection
@@ -35,7 +37,9 @@ use Sabre\DAV\Exception\NotFound;
  *
  * @package OCA\DAV\Comments
  */
-class EntityCollection extends RootCollection {
+class EntityCollection extends RootCollection implements \Sabre\DAV\IProperties {
+       const PROPERTY_NAME_READ_MARKER  = '{http://owncloud.org/ns}readMarker';
+
        /** @var  Folder */
        protected $fileRoot;
 
@@ -159,5 +163,37 @@ class EntityCollection extends RootCollection {
                        return false;
                }
        }
+
+       /**
+        * Sets the read marker to the specified date for the logged in user
+        *
+        * @param \DateTime $value
+        * @return bool
+        */
+       public function setReadMarker($value) {
+               $dateTime = new \DateTime($value);
+               $user = $this->userSession->getUser();
+               $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user);
+               return true;
+       }
+
+       /**
+        * @inheritdoc
+        */
+       function propPatch(PropPatch $propPatch) {
+               $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']);
+       }
+
+       /**
+        * @inheritdoc
+        */
+       function getProperties($properties) {
+               $marker = null;
+               $user = $this->userSession->getUser();
+               if(!is_null($user)) {
+                       $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user);
+               }
+               return [self::PROPERTY_NAME_READ_MARKER => $marker];
+       }
 }
 
index 81442c7a873b0303be9004c48bccd0e8ec971d62..5bf155f12ba7e6792bc09b64c7b22fc572977d4a 100644 (file)
@@ -28,6 +28,7 @@ class EntityCollection extends \Test\TestCase {
        protected $userManager;
        protected $logger;
        protected $collection;
+       protected $userSession;
 
        public function setUp() {
                parent::setUp();
@@ -35,6 +36,7 @@ class EntityCollection extends \Test\TestCase {
                $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager');
                $this->folder = $this->getMock('\OCP\Files\Folder');
                $this->userManager = $this->getMock('\OCP\IUserManager');
+               $this->userSession = $this->getMock('\OCP\IUserSession');
                $this->logger = $this->getMock('\OCP\ILogger');
 
                $this->collection = new \OCA\DAV\Comments\EntityCollection(
@@ -43,6 +45,7 @@ class EntityCollection extends \Test\TestCase {
                        $this->commentsManager,
                        $this->folder,
                        $this->userManager,
+                       $this->userSession,
                        $this->logger
                );
        }
index e8a88c4e2cbb6c0d2c0943ee022c9263f5afeb55..f3aa2dbd71fdffb45003401a736e100b07ebcdb2 100644 (file)
@@ -30,6 +30,7 @@ class EntityTypeCollection extends \Test\TestCase {
        protected $userManager;
        protected $logger;
        protected $collection;
+       protected $userSession;
 
        public function setUp() {
                parent::setUp();
@@ -37,6 +38,7 @@ class EntityTypeCollection extends \Test\TestCase {
                $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager');
                $this->folder = $this->getMock('\OCP\Files\Folder');
                $this->userManager = $this->getMock('\OCP\IUserManager');
+               $this->userSession = $this->getMock('\OCP\IUserSession');
                $this->logger = $this->getMock('\OCP\ILogger');
 
                $this->collection = new \OCA\DAV\Comments\EntityTypeCollection(
@@ -44,6 +46,7 @@ class EntityTypeCollection extends \Test\TestCase {
                        $this->commentsManager,
                        $this->folder,
                        $this->userManager,
+                       $this->userSession,
                        $this->logger
                );
        }