diff options
author | Joas Schilling <coding@schilljs.com> | 2022-01-21 13:42:04 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-01-21 13:42:04 +0100 |
commit | 1ceba648635024c7b198d29239e23595347e7685 (patch) | |
tree | ab0411ed7f280c3c0ee00aebe5f3a50e7aa6ed6d /lib/private/Comments | |
parent | 5ad7309c5500f2ad16d51403f1fb6d491b070f70 (diff) | |
download | nextcloud-server-1ceba648635024c7b198d29239e23595347e7685.tar.gz nextcloud-server-1ceba648635024c7b198d29239e23595347e7685.zip |
Allow to get comments with a given set of verbs
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Comments')
-rw-r--r-- | lib/private/Comments/Manager.php | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index d62db2926fb..680c04dab03 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -412,6 +412,37 @@ class Manager implements ICommentsManager { int $limit = 30, bool $includeLastKnown = false ): array { + return $this->getCommentsWithVerbForObjectSinceComment( + $objectType, + $objectId, + [], + $lastKnownCommentId, + $sortDirection, + $limit, + $includeLastKnown + ); + } + + /** + * @param string $objectType the object type, e.g. 'files' + * @param string $objectId the id of the object + * @param string[] $verbs List of verbs to filter by + * @param int $lastKnownCommentId the last known comment (will be used as offset) + * @param string $sortDirection direction of the comments (`asc` or `desc`) + * @param int $limit optional, number of maximum comments to be returned. if + * set to 0, all comments are returned. + * @param bool $includeLastKnown + * @return IComment[] + */ + public function getCommentsWithVerbForObjectSinceComment( + string $objectType, + string $objectId, + array $verbs, + int $lastKnownCommentId, + string $sortDirection = 'asc', + int $limit = 30, + bool $includeLastKnown = false + ): array { $comments = []; $query = $this->dbConn->getQueryBuilder(); @@ -426,6 +457,10 @@ class Manager implements ICommentsManager { $query->setMaxResults($limit); } + if (!empty($verbs)) { + $query->andWhere($query->expr()->in('verb', $query->createNamedParameter($verbs, IQueryBuilder::PARAM_STR_ARRAY))); + } + $lastKnownComment = $lastKnownCommentId > 0 ? $this->getLastKnownComment( $objectType, $objectId, @@ -681,18 +716,7 @@ class Manager implements ICommentsManager { return $this->getNumberOfCommentsWithVerbsForObjectSinceComment($objectType, $objectId, $lastRead, [$verb]); } - $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))); - - $result = $query->executeQuery(); - $data = $result->fetch(); - $result->closeCursor(); - - return (int) ($data['num_messages'] ?? 0); + return $this->getNumberOfCommentsWithVerbsForObjectSinceComment($objectType, $objectId, $lastRead, []); } /** @@ -709,8 +733,11 @@ class Manager implements ICommentsManager { ->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))); + ->andWhere($query->expr()->gt('id', $query->createNamedParameter($lastRead))); + + if (!empty($verbs)) { + $query->andWhere($query->expr()->in('verb', $query->createNamedParameter($verbs, IQueryBuilder::PARAM_STR_ARRAY))); + } $result = $query->executeQuery(); $data = $result->fetch(); |