|
|
|
|
@ -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; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|