aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-11-26 12:29:44 +0100
committerJoas Schilling <coding@schilljs.com>2021-11-26 12:29:44 +0100
commit2166cfde9ec1296bbdcf7d3a6cee83d2b52be853 (patch)
treebc6f7500dfb63ec961c43c6022406296eed55e7e /lib/private
parentaee3bb42aeb716ff6c60401cd60ec7d6d7a36bec (diff)
downloadnextcloud-server-2166cfde9ec1296bbdcf7d3a6cee83d2b52be853.tar.gz
nextcloud-server-2166cfde9ec1296bbdcf7d3a6cee83d2b52be853.zip
Allow to count comments with multiple verbs
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Comments/Manager.php32
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index 21caf6823f8..d62db2926fb 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -677,6 +677,10 @@ class Manager implements ICommentsManager {
* @since 21.0.0
*/
public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int {
+ if ($verb !== '') {
+ return $this->getNumberOfCommentsWithVerbsForObjectSinceComment($objectType, $objectId, $lastRead, [$verb]);
+ }
+
$query = $this->dbConn->getQueryBuilder();
$query->select($query->func()->count('id', 'num_messages'))
->from('comments')
@@ -684,11 +688,31 @@ class Manager implements ICommentsManager {
->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->executeQuery();
+ $data = $result->fetch();
+ $result->closeCursor();
- $result = $query->execute();
+ return (int) ($data['num_messages'] ?? 0);
+ }
+
+ /**
+ * @param string $objectType
+ * @param string $objectId
+ * @param int $lastRead
+ * @param string[] $verbs
+ * @return int
+ * @since 24.0.0
+ */
+ public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): 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)))
+ ->andWhere($query->expr()->in('verb', $query->createNamedParameter($verbs, IQueryBuilder::PARAM_STR_ARRAY)));
+
+ $result = $query->executeQuery();
$data = $result->fetch();
$result->closeCursor();