diff options
Diffstat (limited to 'apps/dav/lib/comments/commentnode.php')
-rw-r--r-- | apps/dav/lib/comments/commentnode.php | 39 |
1 files changed, 35 insertions, 4 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; } |