diff options
author | Anna Larch <anna@nextcloud.com> | 2023-11-24 01:49:30 +0100 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2023-11-28 10:28:06 +0100 |
commit | f19645adab404a9c2642b42ec335bf2830dd8aa7 (patch) | |
tree | 3f97f43788aadabce26c1a859c669274639fa695 /lib | |
parent | 53f31498049cf0dcd61c6ef1d840801bd81f055c (diff) | |
download | nextcloud-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')
-rw-r--r-- | lib/private/User/AvailabilityCoordinator.php | 50 | ||||
-rw-r--r-- | lib/private/UserStatus/ISettableProvider.php | 3 | ||||
-rw-r--r-- | lib/private/UserStatus/Manager.php | 4 | ||||
-rw-r--r-- | lib/public/User/IAvailabilityCoordinator.php | 16 | ||||
-rw-r--r-- | lib/public/UserStatus/IManager.php | 4 | ||||
-rw-r--r-- | lib/public/UserStatus/IUserStatus.php | 6 |
6 files changed, 60 insertions, 23 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); + } } diff --git a/lib/private/UserStatus/ISettableProvider.php b/lib/private/UserStatus/ISettableProvider.php index 88a107d1f86..957d3274f1d 100644 --- a/lib/private/UserStatus/ISettableProvider.php +++ b/lib/private/UserStatus/ISettableProvider.php @@ -39,8 +39,9 @@ interface ISettableProvider extends IProvider { * @param string $messageId The new message id. * @param string $status The new status. * @param bool $createBackup If true, this will store the old status so that it is possible to revert it later (e.g. after a call). + * @param string|null $customMessage */ - public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup): void; + public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup, ?string $customMessage = null): void; /** * Revert an automatically set user status. For example after leaving a call, diff --git a/lib/private/UserStatus/Manager.php b/lib/private/UserStatus/Manager.php index e255e24c70e..a5594158c1e 100644 --- a/lib/private/UserStatus/Manager.php +++ b/lib/private/UserStatus/Manager.php @@ -104,13 +104,13 @@ class Manager implements IManager { $this->provider = $provider; } - public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false): void { + public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void { $this->setupProvider(); if (!$this->provider || !($this->provider instanceof ISettableProvider)) { return; } - $this->provider->setUserStatus($userId, $messageId, $status, $createBackup); + $this->provider->setUserStatus($userId, $messageId, $status, $createBackup, $customMessage); } public function revertUserStatus(string $userId, string $messageId, string $status): void { diff --git a/lib/public/User/IAvailabilityCoordinator.php b/lib/public/User/IAvailabilityCoordinator.php index 749241f13bc..3a79e39b7b7 100644 --- a/lib/public/User/IAvailabilityCoordinator.php +++ b/lib/public/User/IAvailabilityCoordinator.php @@ -48,4 +48,20 @@ interface IAvailabilityCoordinator { * @since 28.0.0 */ public function getCurrentOutOfOfficeData(IUser $user): ?IOutOfOfficeData; + + /** + * Reset the absence cache to null + * + * @since 28.0.0 + */ + public function clearCache(string $userId): void; + + /** + * Is the absence in effect at this moment + * + * @param IOutOfOfficeData $data + * @return bool + * @since 28.0.0 + */ + public function isInEffect(IOutOfOfficeData $data): bool; } diff --git a/lib/public/UserStatus/IManager.php b/lib/public/UserStatus/IManager.php index 9cc8eaad8ee..a85c1894c65 100644 --- a/lib/public/UserStatus/IManager.php +++ b/lib/public/UserStatus/IManager.php @@ -52,9 +52,11 @@ interface IManager { * @param string $messageId The id of the predefined message. * @param string $status The status to assign * @param bool $createBackup If true, this will store the old status so that it is possible to revert it later (e.g. after a call). + * @param string|null $customMessage * @since 23.0.0 + * @since 28.0.0 Optional parameter $customMessage was added */ - public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false): void; + public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void; /** * Revert an automatically set user status. For example after leaving a call, diff --git a/lib/public/UserStatus/IUserStatus.php b/lib/public/UserStatus/IUserStatus.php index c96d07d298b..f5005e5616b 100644 --- a/lib/public/UserStatus/IUserStatus.php +++ b/lib/public/UserStatus/IUserStatus.php @@ -85,6 +85,12 @@ interface IUserStatus { * @var string * @since 28.0.0 */ + public const MESSAGE_VACATION = 'vacationing'; + + /** + * @var string + * @since 28.0.0 + */ public const MESSAGE_CALENDAR_BUSY = 'meeting'; /** |