summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Comments/Manager.php44
-rw-r--r--lib/public/Comments/ICommentsManager.php17
2 files changed, 61 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
diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php
index cfdf3d7fdb7..60f925afa34 100644
--- a/lib/public/Comments/ICommentsManager.php
+++ b/lib/public/Comments/ICommentsManager.php
@@ -200,6 +200,23 @@ interface ICommentsManager {
public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int;
/**
+ * @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;
+
+ /**
* Get the number of unread comments for all files in a folder
*
* @param int $folderId