diff options
author | Joas Schilling <coding@schilljs.com> | 2020-10-21 09:18:51 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-10-21 09:18:51 +0200 |
commit | d462439a6311dce60b8a89583af054f2ff120fac (patch) | |
tree | 508192a1117af5eaba6d264625167538b57372f2 /lib/private | |
parent | 89651c5233e4e5e71213f7c05c1d94e23937e171 (diff) | |
download | nextcloud-server-d462439a6311dce60b8a89583af054f2ff120fac.tar.gz nextcloud-server-d462439a6311dce60b8a89583af054f2ff120fac.zip |
Get the last comment date for a list of actors (to allow sorting mention suggestions e.g.)
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Comments/Manager.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 1077ea554de..68542580fcf 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -31,6 +31,7 @@ namespace OC\Comments; use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Exception\InvalidFieldNameException; use OCA\Comments\AppInfo\Application; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\CommentsEvent; use OCP\Comments\IComment; use OCP\Comments\ICommentsEventHandler; @@ -55,6 +56,9 @@ class Manager implements ICommentsManager { /** @var IConfig */ protected $config; + /** @var ITimeFactory */ + protected $timeFactory; + /** @var IInitialStateService */ protected $initialStateService; @@ -73,10 +77,12 @@ class Manager implements ICommentsManager { public function __construct(IDBConnection $dbConn, LoggerInterface $logger, IConfig $config, + ITimeFactory $timeFactory, IInitialStateService $initialStateService) { $this->dbConn = $dbConn; $this->logger = $logger; $this->config = $config; + $this->timeFactory = $timeFactory; $this->initialStateService = $initialStateService; } @@ -666,6 +672,44 @@ class Manager implements ICommentsManager { } /** + * @param string $objectType + * @param string $objectId + * @param string $verb + * @param string $actorType + * @param string[] $actors + * @return array + * @since 21.0.0 + */ + public function getLastCommentDateByActor( + string $objectType, + string $objectId, + string $verb, + string $actorType, + array $actors + ): array { + $lastComments = []; + + $query = $this->dbConn->getQueryBuilder(); + $query->select('actor_id') + ->selectAlias($query->createFunction('MAX(' . $query->getColumnName('creation_timestamp') . ')'), 'last_comment') + ->from('comments') + ->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType))) + ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))) + ->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))) + ->andWhere($query->expr()->eq('actor_type', $query->createNamedParameter($actorType))) + ->andWhere($query->expr()->in('actor_id', $query->createNamedParameter($actors, IQueryBuilder::PARAM_STR_ARRAY))) + ->groupBy('actor_id'); + + $result = $query->execute(); + while ($row = $result->fetch()) { + $lastComments[$row['actor_id']] = $this->timeFactory->getDateTime($row['last_comment']); + } + $result->closeCursor(); + + return $lastComments; + } + + /** * Get the number of unread comments for all files in a folder * * @param int $folderId |