Skip to content

Commit

Permalink
Merge pull request #10444 from nextcloud/feature/noid/allow-to-filter…
Browse files Browse the repository at this point in the history
…-unread-count-by-verb

Allow to filter the unread count by verb
  • Loading branch information
blizzz authored Jul 31, 2018
2 parents ef85ef0 + 66945f9 commit c39bc16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/private/Comments/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,13 @@ public function search(string $search, string $objectType, string $objectId, str
* @param $objectId string the id of the object
* @param \DateTime $notOlderThan optional, timestamp of the oldest comments
* that may be returned
* @param string $verb Limit the verb of the comment - Added in 14.0.0
* @return Int
* @since 9.0.0
*/
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) {
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '') {
$qb = $this->dbConn->getQueryBuilder();
$query = $qb->select($qb->createFunction('COUNT(`id`)'))
$query = $qb->select($qb->createFunction('COUNT(' . $qb->getColumnName('id') . ')'))
->from('comments')
->where($qb->expr()->eq('object_type', $qb->createParameter('type')))
->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id')))
Expand All @@ -564,6 +565,10 @@ public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $
->setParameter('notOlderThan', $notOlderThan, 'datetime');
}

if ($verb !== '') {
$query->andWhere($qb->expr()->eq('verb', $qb->createNamedParameter($verb)));
}

$resultStatement = $query->execute();
$data = $resultStatement->fetch(\PDO::FETCH_NUM);
$resultStatement->closeCursor();
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Comments/ICommentsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ public function search(string $search, string $objectType, string $objectId, str
* @param $objectId string the id of the object
* @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
* that may be returned
* @param string $verb Limit the verb of the comment - Added in 14.0.0
* @return Int
* @since 9.0.0
*/
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null);
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '');

/**
* Get the number of unread comments for all files in a folder
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Comments/FakeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getForObjectSince(
int $limit = 30
): array { return []; }

public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) {}
public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '') {}

public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array {
return [];
Expand Down

0 comments on commit c39bc16

Please sign in to comment.