use OCP\Files\Folder;
use OCP\ILogger;
use OCP\IUserManager;
+use OCP\IUserSession;
use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\PropPatch;
/**
* Class EntityCollection
*
* @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;
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];
+ }
}
protected $userManager;
protected $logger;
protected $collection;
+ protected $userSession;
public function setUp() {
parent::setUp();
$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(
$this->commentsManager,
$this->folder,
$this->userManager,
+ $this->userSession,
$this->logger
);
}
protected $userManager;
protected $logger;
protected $collection;
+ protected $userSession;
public function setUp() {
parent::setUp();
$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(
$this->commentsManager,
$this->folder,
$this->userManager,
+ $this->userSession,
$this->logger
);
}