|
|
|
|
@ -22,6 +22,7 @@ class CommentPropertiesPlugin extends ServerPlugin {
|
|
|
|
|
|
|
|
|
|
protected ?Server $server = null;
|
|
|
|
|
private array $cachedUnreadCount = [];
|
|
|
|
|
private array $cachedCount = [];
|
|
|
|
|
private array $cachedDirectories = [];
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
@ -48,7 +49,11 @@ class CommentPropertiesPlugin extends ServerPlugin {
|
|
|
|
|
$this->server->on('propFind', [$this, 'handleGetProperties']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function cacheDirectory(Directory $directory): void {
|
|
|
|
|
private function cacheDirectory(Directory $directory, PropFind $propFind): void {
|
|
|
|
|
if (is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) && is_null($propFind->getStatus(self::PROPERTY_NAME_COUNT))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$children = $directory->getChildren();
|
|
|
|
|
|
|
|
|
|
$ids = [];
|
|
|
|
|
@ -66,24 +71,39 @@ class CommentPropertiesPlugin extends ServerPlugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ids[] = (string)$directory->getId();
|
|
|
|
|
$unread = $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', $ids, $this->userSession->getUser());
|
|
|
|
|
if (!is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD))) {
|
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
|
if ($user) {
|
|
|
|
|
$unread = $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', $ids, $user);
|
|
|
|
|
foreach ($unread as $id => $count) {
|
|
|
|
|
$this->cachedUnreadCount[(int)$id] = $count;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
|
$this->cachedUnreadCount[(int)$id] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($unread as $id => $count) {
|
|
|
|
|
$this->cachedUnreadCount[(int)$id] = $count;
|
|
|
|
|
if (!is_null($propFind->getStatus(self::PROPERTY_NAME_COUNT))) {
|
|
|
|
|
$commentCounts = $this->commentsManager->getNumberOfCommentsForObjects('files', $ids);
|
|
|
|
|
foreach ($commentCounts as $id => $count) {
|
|
|
|
|
$this->cachedCount[(int)$id] = $count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function preloadCollection(PropFind $propFind, ICollection $collection):
|
|
|
|
|
void {
|
|
|
|
|
private function preloadCollection(PropFind $propFind, ICollection $collection): void {
|
|
|
|
|
if (!($collection instanceof Directory)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$collectionPath = $collection->getPath();
|
|
|
|
|
if (!isset($this->cachedDirectories[$collectionPath]) && $propFind->getStatus(
|
|
|
|
|
self::PROPERTY_NAME_UNREAD
|
|
|
|
|
) !== null) {
|
|
|
|
|
$this->cacheDirectory($collection);
|
|
|
|
|
if (!isset($this->cachedDirectories[$collectionPath]) && (
|
|
|
|
|
$propFind->getStatus(self::PROPERTY_NAME_UNREAD) !== null
|
|
|
|
|
|| $propFind->getStatus(self::PROPERTY_NAME_COUNT) !== null)) {
|
|
|
|
|
$this->cacheDirectory($collection, $propFind);
|
|
|
|
|
$this->cachedDirectories[$collectionPath] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -105,7 +125,7 @@ class CommentPropertiesPlugin extends ServerPlugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node): int {
|
|
|
|
|
return $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId());
|
|
|
|
|
return $this->cachedCount[$node->getId()] ?? $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$propFind->handle(self::PROPERTY_NAME_HREF, function () use ($node): ?string {
|
|
|
|
|
@ -141,8 +161,7 @@ class CommentPropertiesPlugin extends ServerPlugin {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$lastRead = $this->commentsManager->getReadMark('files', (string)$node->getId(), $user);
|
|
|
|
|
|
|
|
|
|
return $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId(), $lastRead);
|
|
|
|
|
$objectId = (string)$node->getId();
|
|
|
|
|
return $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', [$objectId], $user)[$objectId];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|