diff options
author | Joas Schilling <coding@schilljs.com> | 2020-10-21 09:15:38 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-10-21 09:15:38 +0200 |
commit | 326640462b7d04f6bbbc57858e8f978c9c46afcc (patch) | |
tree | bb84ef83b1c1612a33639f83694c643a43ac21a9 | |
parent | 2cc35cc65d251ac52e1e09fe52381ccbf64eb89f (diff) | |
download | nextcloud-server-326640462b7d04f6bbbc57858e8f978c9c46afcc.tar.gz nextcloud-server-326640462b7d04f6bbbc57858e8f978c9c46afcc.zip |
Add methods to get the number of comments and last comment since a date
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/Comments/Manager.php | 55 | ||||
-rw-r--r-- | lib/public/Comments/ICommentsManager.php | 20 |
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index dc449cc4d4b..9e31f448338 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -592,6 +592,61 @@ class Manager implements ICommentsManager { } /** + * @param string $objectType + * @param string $objectId + * @param int $lastRead + * @param string $verb + * @return int + * @since 21.0.0 + */ + public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int { + $query = $this->dbConn->getQueryBuilder(); + $query->select($query->func()->count('id', 'num_messages')) + ->from('comments') + ->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType))) + ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))) + ->andWhere($query->expr()->gt('id', $query->createNamedParameter($lastRead))); + + if ($verb !== '') { + $query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))); + } + + $result = $query->execute(); + $data = $result->fetch(); + $result->closeCursor(); + + return (int) ($data['num_messages'] ?? 0); + } + + /** + * @param string $objectType + * @param string $objectId + * @param \DateTime $beforeDate + * @param string $verb + * @return int + * @since 21.0.0 + */ + public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int { + $query = $this->dbConn->getQueryBuilder(); + $query->select('id') + ->from('comments') + ->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType))) + ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))) + ->andWhere($query->expr()->lt('creation_timestamp', $query->createNamedParameter($beforeDate, IQueryBuilder::PARAM_DATE))) + ->orderBy('creation_timestamp', 'desc'); + + if ($verb !== '') { + $query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))); + } + + $result = $query->execute(); + $data = $result->fetch(); + $result->closeCursor(); + + return (int) ($data['id'] ?? 0); + } + + /** * Get the number of unread comments for all files in a folder * * @param int $folderId diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index 718391f7145..6e867e2f17e 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -167,6 +167,26 @@ interface ICommentsManager { public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = ''); /** + * @param string $objectType + * @param string $objectId + * @param int $lastRead + * @param string $verb + * @return int + * @since 21.0.0 + */ + public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int; + + /** + * @param string $objectType + * @param string $objectId + * @param \DateTime $beforeDate + * @param string $verb + * @return int + * @since 21.0.0 + */ + public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int; + + /** * Get the number of unread comments for all files in a folder * * @param int $folderId |