From f19645adab404a9c2642b42ec335bf2830dd8aa7 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Fri, 24 Nov 2023 01:49:30 +0100 Subject: enh(userstatus): add OOO automation and remove calendar automation Signed-off-by: Anna Larch --- lib/private/User/AvailabilityCoordinator.php | 50 +++++++++++++++++----------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'lib/private/User') 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); + } } -- cgit v1.2.3