aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/User
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2023-11-24 01:49:30 +0100
committerAnna Larch <anna@nextcloud.com>2023-11-28 10:28:06 +0100
commitf19645adab404a9c2642b42ec335bf2830dd8aa7 (patch)
tree3f97f43788aadabce26c1a859c669274639fa695 /lib/private/User
parent53f31498049cf0dcd61c6ef1d840801bd81f055c (diff)
downloadnextcloud-server-f19645adab404a9c2642b42ec335bf2830dd8aa7.tar.gz
nextcloud-server-f19645adab404a9c2642b42ec335bf2830dd8aa7.zip
enh(userstatus): add OOO automation and remove calendar automation
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib/private/User')
-rw-r--r--lib/private/User/AvailabilityCoordinator.php50
1 files changed, 31 insertions, 19 deletions
diff --git a/lib/private/User/AvailabilityCoordinator.php b/lib/private/User/AvailabilityCoordinator.php
index e33a0aa1558..c32c3005c32 100644
--- a/lib/private/User/AvailabilityCoordinator.php
+++ b/lib/private/User/AvailabilityCoordinator.php
@@ -29,8 +29,7 @@ namespace OC\User;
use JsonException;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\TimezoneService;
-use OCA\DAV\Db\AbsenceMapper;
-use OCP\AppFramework\Db\DoesNotExistException;
+use OCA\DAV\Service\AbsenceService;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
@@ -44,8 +43,8 @@ class AvailabilityCoordinator implements IAvailabilityCoordinator {
public function __construct(
ICacheFactory $cacheFactory,
- private AbsenceMapper $absenceMapper,
private IConfig $config,
+ private AbsenceService $absenceService,
private LoggerInterface $logger,
private TimezoneService $timezoneService,
) {
@@ -53,11 +52,7 @@ class AvailabilityCoordinator implements IAvailabilityCoordinator {
}
public function isEnabled(): bool {
- return $this->config->getAppValue(
- Application::APP_ID,
- 'hide_absence_settings',
- 'no',
- ) === 'no';
+ return $this->config->getAppValue(Application::APP_ID, 'hide_absence_settings', 'no') === 'no';
}
private function getCachedOutOfOfficeData(IUser $user): ?OutOfOfficeData {
@@ -106,22 +101,39 @@ class AvailabilityCoordinator implements IAvailabilityCoordinator {
}
public function getCurrentOutOfOfficeData(IUser $user): ?IOutOfOfficeData {
- $cachedData = $this->getCachedOutOfOfficeData($user);
- if ($cachedData !== null) {
- return $cachedData;
+ $timezone = $this->getCachedTimezone($user->getUID());
+ if ($timezone === null) {
+ $timezone = $this->timezoneService->getUserTimezone($user->getUID()) ?? $this->timezoneService->getDefaultTimezone();
+ $this->setCachedTimezone($user->getUID(), $timezone);
}
- try {
- $absenceData = $this->absenceMapper->findByUserId($user->getUID());
- } catch (DoesNotExistException $e) {
- return null;
+ $data = $this->getCachedOutOfOfficeData($user);
+ if ($data === null) {
+ $absenceData = $this->absenceService->getAbsence($user->getUID());
+ if ($absenceData === null) {
+ return null;
+ }
+ $data = $absenceData->toOutOufOfficeData($user, $timezone);
}
- $data = $absenceData->toOutOufOfficeData(
- $user,
- $this->timezoneService->getUserTimezone($user->getUID()) ?? $this->timezoneService->getDefaultTimezone(),
- );
$this->setCachedOutOfOfficeData($data);
return $data;
}
+
+ private function getCachedTimezone(string $userId): ?string {
+ return $this->cache->get($userId . '_timezone') ?? null;
+ }
+
+ private function setCachedTimezone(string $userId, string $timezone): void {
+ $this->cache->set($userId . '_timezone', $timezone, 3600);
+ }
+
+ public function clearCache(string $userId): void {
+ $this->cache->set($userId, null, 300);
+ $this->cache->set($userId . '_timezone', null, 3600);
+ }
+
+ public function isInEffect(IOutOfOfficeData $data): bool {
+ return $this->absenceService->isInEffect($data);
+ }
}