summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/comments/commentnode.php39
-rw-r--r--apps/dav/lib/comments/entitycollection.php19
-rw-r--r--apps/dav/lib/comments/entitytypecollection.php5
-rw-r--r--apps/dav/lib/comments/rootcollection.php1
4 files changed, 58 insertions, 6 deletions
diff --git a/apps/dav/lib/comments/commentnode.php b/apps/dav/lib/comments/commentnode.php
index eb26e350a42..a5d508dd198 100644
--- a/apps/dav/lib/comments/commentnode.php
+++ b/apps/dav/lib/comments/commentnode.php
@@ -26,12 +26,17 @@ use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\ILogger;
use OCP\IUserManager;
+use OCP\IUserSession;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\PropPatch;
class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
const NS_OWNCLOUD = 'http://owncloud.org/ns';
+ 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';
+
/** @var IComment */
public $comment;
@@ -47,18 +52,23 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
/** @var IUserManager */
protected $userManager;
+ /** @var IUserSession */
+ protected $userSession;
+
/**
* CommentNode constructor.
*
* @param ICommentsManager $commentsManager
* @param IComment $comment
* @param IUserManager $userManager
+ * @param IUserSession $userSession
* @param ILogger $logger
*/
public function __construct(
ICommentsManager $commentsManager,
IComment $comment,
IUserManager $userManager,
+ IUserSession $userSession,
ILogger $logger
) {
$this->commentsManager = $commentsManager;
@@ -74,6 +84,7 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
$this->properties[$name] = $getter;
}
$this->userManager = $userManager;
+ $this->userSession = $userSession;
}
/**
@@ -87,15 +98,17 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
'{http://owncloud.org/ns}parentId',
'{http://owncloud.org/ns}topmostParentId',
'{http://owncloud.org/ns}childrenCount',
- '{http://owncloud.org/ns}message',
'{http://owncloud.org/ns}verb',
'{http://owncloud.org/ns}actorType',
'{http://owncloud.org/ns}actorId',
- '{http://owncloud.org/ns}actorDisplayName',
'{http://owncloud.org/ns}creationDateTime',
'{http://owncloud.org/ns}latestChildDateTime',
'{http://owncloud.org/ns}objectType',
'{http://owncloud.org/ns}objectId',
+ // re-used property names are defined as constants
+ self::PROPERTY_NAME_MESSAGE,
+ self::PROPERTY_NAME_ACTOR_DISPLAYNAME,
+ self::PROPERTY_NAME_UNREAD
];
}
@@ -169,7 +182,7 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
*/
function propPatch(PropPatch $propPatch) {
// other properties than 'message' are read only
- $propPatch->handle('{'.self::NS_OWNCLOUD.'}message', [$this, 'updateComment']);
+ $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']);
}
/**
@@ -201,8 +214,26 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
if($this->comment->getActorType() === 'users') {
$user = $this->userManager->get($this->comment->getActorId());
$displayName = is_null($user) ? null : $user->getDisplayName();
- $result['{' . self::NS_OWNCLOUD . '}actorDisplayName'] = $displayName;
+ $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName;
+ }
+
+ $unread = null;
+ $user = $this->userSession->getUser();
+ if(!is_null($user)) {
+ $readUntil = $this->commentsManager->getReadMark(
+ $this->comment->getObjectType(),
+ $this->comment->getObjectId(),
+ $user
+ );
+ if(is_null($readUntil)) {
+ $unread = 'true';
+ } else {
+ $unread = $this->comment->getCreationDateTime() > $readUntil;
+ // re-format for output
+ $unread = $unread ? 'true' : 'false';
+ }
}
+ $result[self::PROPERTY_NAME_UNREAD] = $unread;
return $result;
}
diff --git a/apps/dav/lib/comments/entitycollection.php b/apps/dav/lib/comments/entitycollection.php
index a93569f6e4f..0cc5526c529 100644
--- a/apps/dav/lib/comments/entitycollection.php
+++ b/apps/dav/lib/comments/entitycollection.php
@@ -51,6 +51,7 @@ class EntityCollection extends RootCollection {
* @param ICommentsManager $commentsManager
* @param Folder $fileRoot
* @param IUserManager $userManager
+ * @param IUserSession $userSession
* @param ILogger $logger
*/
public function __construct(
@@ -59,6 +60,7 @@ class EntityCollection extends RootCollection {
ICommentsManager $commentsManager,
Folder $fileRoot,
IUserManager $userManager,
+ IUserSession $userSession,
ILogger $logger
) {
foreach(['id', 'name'] as $property) {
@@ -73,6 +75,7 @@ class EntityCollection extends RootCollection {
$this->fileRoot = $fileRoot;
$this->logger = $logger;
$this->userManager = $userManager;
+ $this->userSession = $userSession;
}
/**
@@ -97,7 +100,13 @@ class EntityCollection extends RootCollection {
function getChild($name) {
try {
$comment = $this->commentsManager->get($name);
- return new CommentNode($this->commentsManager, $comment, $this->userManager, $this->logger);
+ return new CommentNode(
+ $this->commentsManager,
+ $comment,
+ $this->userManager,
+ $this->userSession,
+ $this->logger
+ );
} catch (\OCP\Comments\NotFoundException $e) {
throw new NotFound();
}
@@ -125,7 +134,13 @@ class EntityCollection extends RootCollection {
$comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime);
$result = [];
foreach($comments as $comment) {
- $result[] = new CommentNode($this->commentsManager, $comment, $this->userManager, $this->logger);
+ $result[] = new CommentNode(
+ $this->commentsManager,
+ $comment,
+ $this->userManager,
+ $this->userSession,
+ $this->logger
+ );
}
return $result;
}
diff --git a/apps/dav/lib/comments/entitytypecollection.php b/apps/dav/lib/comments/entitytypecollection.php
index f49aac747c2..6bc42484207 100644
--- a/apps/dav/lib/comments/entitytypecollection.php
+++ b/apps/dav/lib/comments/entitytypecollection.php
@@ -25,6 +25,7 @@ use OCP\Comments\ICommentsManager;
use OCP\Files\Folder;
use OCP\ILogger;
use OCP\IUserManager;
+use OCP\IUserSession;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
@@ -51,6 +52,7 @@ class EntityTypeCollection extends RootCollection {
* @param ICommentsManager $commentsManager
* @param Folder $fileRoot
* @param IUserManager $userManager
+ * @param IUserSession $userSession
* @param ILogger $logger
*/
public function __construct(
@@ -58,6 +60,7 @@ class EntityTypeCollection extends RootCollection {
ICommentsManager $commentsManager,
Folder $fileRoot,
IUserManager $userManager,
+ IUserSession $userSession,
ILogger $logger
) {
$name = trim($name);
@@ -69,6 +72,7 @@ class EntityTypeCollection extends RootCollection {
$this->fileRoot = $fileRoot;
$this->logger = $logger;
$this->userManager = $userManager;
+ $this->userSession = $userSession;
}
/**
@@ -91,6 +95,7 @@ class EntityTypeCollection extends RootCollection {
$this->commentsManager,
$this->fileRoot,
$this->userManager,
+ $this->userSession,
$this->logger
);
}
diff --git a/apps/dav/lib/comments/rootcollection.php b/apps/dav/lib/comments/rootcollection.php
index aec8e655667..cda666f7162 100644
--- a/apps/dav/lib/comments/rootcollection.php
+++ b/apps/dav/lib/comments/rootcollection.php
@@ -98,6 +98,7 @@ class RootCollection implements ICollection {
$this->commentsManager,
$userFolder,
$this->userManager,
+ $this->userSession,
$this->logger
);
}