diff options
author | Robin Appelman <robin@icewind.nl> | 2024-03-07 15:26:11 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2024-03-07 19:19:07 +0100 |
commit | eb5832b8fa654f6677f8a81c43300e03e05ca429 (patch) | |
tree | 7231da5a3cfae56aa400f037c6f38ab22490c081 /lib | |
parent | be3449c42d819205fb627c5e74a1d8dfde0c0520 (diff) | |
download | nextcloud-server-eb5832b8fa654f6677f8a81c43300e03e05ca429.tar.gz nextcloud-server-eb5832b8fa654f6677f8a81c43300e03e05ca429.zip |
refactor: depricate getNumberOfUnreadCommentsForFolder and redo it's implementation based on getNumberOfUnreadCommentsForObjects
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Comments/Manager.php | 86 | ||||
-rw-r--r-- | lib/public/Comments/ICommentsManager.php | 1 |
2 files changed, 27 insertions, 60 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 85b56f9f25c..49b319038cb 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -29,6 +29,7 @@ namespace OC\Comments; use Doctrine\DBAL\Exception\DriverException; +use OCA\DAV\Connector\Sabre\File; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\CommentsEvent; use OCP\Comments\IComment; @@ -36,6 +37,9 @@ use OCP\Comments\ICommentsEventHandler; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Files\FileInfo; +use OCP\Files\Folder; +use OCP\Files\IRootFolder; use OCP\IConfig; use OCP\IDBConnection; use OCP\IEmojiHelper; @@ -46,12 +50,6 @@ use OCP\Util; use Psr\Log\LoggerInterface; class Manager implements ICommentsManager { - protected IDBConnection $dbConn; - protected LoggerInterface $logger; - protected IConfig $config; - protected ITimeFactory $timeFactory; - protected IEmojiHelper $emojiHelper; - protected IInitialStateService $initialStateService; /** @var IComment[] */ protected array $commentsCache = []; @@ -64,18 +62,15 @@ class Manager implements ICommentsManager { /** @var \Closure[] */ protected array $displayNameResolvers = []; - public function __construct(IDBConnection $dbConn, - LoggerInterface $logger, - IConfig $config, - ITimeFactory $timeFactory, - IEmojiHelper $emojiHelper, - IInitialStateService $initialStateService) { - $this->dbConn = $dbConn; - $this->logger = $logger; - $this->config = $config; - $this->timeFactory = $timeFactory; - $this->emojiHelper = $emojiHelper; - $this->initialStateService = $initialStateService; + public function __construct( + protected IDBConnection $dbConn, + protected LoggerInterface $logger, + protected IConfig $config, + protected ITimeFactory $timeFactory, + protected IEmojiHelper $emojiHelper, + protected IInitialStateService $initialStateService, + protected IRootFolder $rootFolder, + ) { } /** @@ -820,54 +815,25 @@ class Manager implements ICommentsManager { /** * Get the number of unread comments for all files in a folder * + * This is unused since 8bd39fccf411195839f2dadee085fad18ec52c23 + * * @param int $folderId * @param IUser $user * @return array [$fileId => $unreadCount] */ public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) { - $qb = $this->dbConn->getQueryBuilder(); - - $query = $qb->select('f.fileid') - ->addSelect($qb->func()->count('c.id', 'num_ids')) - ->from('filecache', 'f') - ->leftJoin('f', 'comments', 'c', $qb->expr()->andX( - $qb->expr()->eq('f.fileid', $qb->expr()->castColumn('c.object_id', IQueryBuilder::PARAM_INT)), - $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')) - )) - ->leftJoin('c', 'comments_read_markers', 'm', $qb->expr()->andX( - $qb->expr()->eq('c.object_id', 'm.object_id'), - $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')) - )) - ->where( - $qb->expr()->andX( - $qb->expr()->eq('f.parent', $qb->createNamedParameter($folderId)), - $qb->expr()->orX( - $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')), - $qb->expr()->isNull('c.object_type') - ), - $qb->expr()->orX( - $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')), - $qb->expr()->isNull('m.object_type') - ), - $qb->expr()->orX( - $qb->expr()->eq('m.user_id', $qb->createNamedParameter($user->getUID())), - $qb->expr()->isNull('m.user_id') - ), - $qb->expr()->orX( - $qb->expr()->gt('c.creation_timestamp', 'm.marker_datetime'), - $qb->expr()->isNull('m.marker_datetime') - ) - ) - )->groupBy('f.fileid'); - - $resultStatement = $query->execute(); - - $results = []; - while ($row = $resultStatement->fetch()) { - $results[$row['fileid']] = (int) $row['num_ids']; + $directory = $this->rootFolder->getFirstNodeById($folderId); + if (!$directory instanceof Folder) { + return []; } - $resultStatement->closeCursor(); - return $results; + $children = $directory->getDirectoryListing(); + $ids = array_map(fn (FileInfo $child) => (string) $child->getId(), $children); + + $ids[] = (string) $directory->getId(); + $counts = $this->getNumberOfUnreadCommentsForObjects('files', $ids, $user); + return array_filter($counts, function (int $count) { + return $count > 0; + }); } /** diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index 152c8deeaf3..3d47be3d951 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -271,6 +271,7 @@ interface ICommentsManager { * @param IUser $user * @return array [$fileId => $unreadCount] * @since 12.0.0 + * @deprecated 29.0.0 use getNumberOfUnreadCommentsForObjects instead */ public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user); |