diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/comments/manager.php | 60 | ||||
-rw-r--r-- | lib/private/comments/managerfactory.php | 3 | ||||
-rw-r--r-- | lib/public/comments/icommentsmanager.php | 29 |
3 files changed, 88 insertions, 4 deletions
diff --git a/lib/private/comments/manager.php b/lib/private/comments/manager.php index 64977c48895..580bc2a8816 100644 --- a/lib/private/comments/manager.php +++ b/lib/private/comments/manager.php @@ -25,7 +25,9 @@ use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; use OCP\IDBConnection; +use OCP\IConfig; use OCP\ILogger; +use OCP\IUser; class Manager implements ICommentsManager { @@ -38,12 +40,17 @@ class Manager implements ICommentsManager { /** @var IComment[] */ protected $commentsCache = []; + /** @var IConfig */ + protected $config; + public function __construct( IDBConnection $dbConn, - ILogger $logger + ILogger $logger, + IConfig $config ) { $this->dbConn = $dbConn; $this->logger = $logger; + $this->config = $config; } /** @@ -346,10 +353,12 @@ class Manager implements ICommentsManager { /** * @param $objectType string the object type, e.g. 'files' * @param $objectId string the id of the object + * @param \DateTime $notOlderThan optional, timestamp of the oldest comments + * that may be returned * @return Int * @since 9.0.0 */ - public function getNumberOfCommentsForObject($objectType, $objectId) { + public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) { $qb = $this->dbConn->getQueryBuilder(); $query = $qb->select($qb->createFunction('COUNT(`id`)')) ->from('comments') @@ -358,6 +367,12 @@ class Manager implements ICommentsManager { ->setParameter('type', $objectType) ->setParameter('id', $objectId); + if(!is_null($notOlderThan)) { + $query + ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) + ->setParameter('notOlderThan', $notOlderThan, 'datetime'); + } + $resultStatement = $query->execute(); $data = $resultStatement->fetch(\PDO::FETCH_NUM); $resultStatement->closeCursor(); @@ -566,4 +581,45 @@ class Manager implements ICommentsManager { return is_int($affectedRows); } + + /** + * sets the read marker for a given file to the specified date for the + * provided user + * + * @param string $objectType + * @param string $objectId + * @param \DateTime $dateTime + * @param IUser $user + * @since 9.0.0 + */ + public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) { + $this->checkRoleParameters('Object', $objectType, $objectId); + $dateTime = $dateTime->format('Y-m-d H:i:s'); + $this->config->setUserValue($user->getUID(), 'comments', 'marker.' . $objectType .'.'. $objectId, $dateTime); + } + + /** + * returns the read marker for a given file to the specified date for the + * provided user. It returns null, when the marker is not present, i.e. + * no comments were marked as read. + * + * @param string $objectType + * @param string $objectId + * @param IUser $user + * @return \DateTime|null + * @since 9.0.0 + */ + public function getReadMark($objectType, $objectId, IUser $user) { + $this->checkRoleParameters('Object', $objectType, $objectId); + $dateTime = $this->config->getUserValue( + $user->getUID(), + 'comments', + 'marker.' . $objectType .'.'. $objectId, + null + ); + if(!is_null($dateTime)) { + $dateTime = new \DateTime($dateTime); + } + return $dateTime; + } } diff --git a/lib/private/comments/managerfactory.php b/lib/private/comments/managerfactory.php index 281e8ca7fef..d3f6c44e539 100644 --- a/lib/private/comments/managerfactory.php +++ b/lib/private/comments/managerfactory.php @@ -51,7 +51,8 @@ class ManagerFactory implements ICommentsManagerFactory { public function getManager() { return new Manager( $this->serverContainer->getDatabaseConnection(), - $this->serverContainer->getLogger() + $this->serverContainer->getLogger(), + $this->serverContainer->getConfig() ); } } diff --git a/lib/public/comments/icommentsmanager.php b/lib/public/comments/icommentsmanager.php index b8fb3ca7f5d..abcc0a7b159 100644 --- a/lib/public/comments/icommentsmanager.php +++ b/lib/public/comments/icommentsmanager.php @@ -115,10 +115,12 @@ interface ICommentsManager { /** * @param $objectType string the object type, e.g. 'files' * @param $objectId string the id of the object + * @param \DateTime $notOlderThan optional, timestamp of the oldest comments + * that may be returned * @return Int * @since 9.0.0 */ - public function getNumberOfCommentsForObject($objectType, $objectId); + public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null); /** * creates a new comment and returns it. At this point of time, it is not @@ -188,4 +190,29 @@ interface ICommentsManager { */ public function deleteCommentsAtObject($objectType, $objectId); + /** + * sets the read marker for a given file to the specified date for the + * provided user + * + * @param string $objectType + * @param string $objectId + * @param \DateTime $dateTime + * @param \OCP\IUser $user + * @since 9.0.0 + */ + public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user); + + /** + * returns the read marker for a given file to the specified date for the + * provided user. It returns null, when the marker is not present, i.e. + * no comments were marked as read. + * + * @param string $objectType + * @param string $objectId + * @param \OCP\IUser $user + * @return \DateTime|null + * @since 9.0.0 + */ + public function getReadMark($objectType, $objectId, \OCP\IUser $user); + } |