diff options
author | Joas Schilling <coding@schilljs.com> | 2022-02-15 15:28:55 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-02-15 16:06:33 +0100 |
commit | 058d1de26012ab829fad915f35b1bb761808ce7b (patch) | |
tree | e336ec7e9956fe07cb8db59642d5f86088068ef6 /apps/user_status/lib/Service | |
parent | 5fcbb1ca62d7cfbffb0e4089f7315cdfe29668b0 (diff) | |
download | nextcloud-server-058d1de26012ab829fad915f35b1bb761808ce7b.tar.gz nextcloud-server-058d1de26012ab829fad915f35b1bb761808ce7b.zip |
Do status and predefined message setting in one go
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_status/lib/Service')
-rw-r--r-- | apps/user_status/lib/Service/StatusService.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php index 5cd5bb83c3a..c7ad7afe322 100644 --- a/apps/user_status/lib/Service/StatusService.php +++ b/apps/user_status/lib/Service/StatusService.php @@ -231,6 +231,7 @@ class StatusService { $userStatus->setStatus(IUserStatus::OFFLINE); $userStatus->setStatusTimestamp(0); $userStatus->setIsUserDefined(false); + $userStatus->setIsBackup(false); } if (!$this->predefinedStatusService->isValidId($messageId)) { @@ -256,6 +257,60 @@ class StatusService { /** * @param string $userId + * @param string $status + * @param string $messageId + * @param bool $createBackup + * @throws InvalidStatusTypeException + * @throws InvalidMessageIdException + */ + public function setUserStatus(string $userId, + string $status, + string $messageId, + bool $createBackup): void { + // Check if status-type is valid + if (!\in_array($status, self::PRIORITY_ORDERED_STATUSES, true)) { + throw new InvalidStatusTypeException('Status-type "' . $status . '" is not supported'); + } + + if (!$this->predefinedStatusService->isValidId($messageId)) { + throw new InvalidMessageIdException('Message-Id "' . $messageId . '" is not supported'); + } + + if ($createBackup) { + if ($this->backupCurrentStatus($userId) === false) { + return; // Already a status set automatically => abort. + } + + // If we just created the backup + $userStatus = new UserStatus(); + $userStatus->setUserId($userId); + } else { + try { + $userStatus = $this->mapper->findByUserId($userId); + } catch (DoesNotExistException $ex) { + $userStatus = new UserStatus(); + $userStatus->setUserId($userId); + } + } + + $userStatus->setStatus($status); + $userStatus->setStatusTimestamp($this->timeFactory->getTime()); + $userStatus->setIsUserDefined(false); + $userStatus->setIsBackup(false); + $userStatus->setMessageId($messageId); + $userStatus->setCustomIcon(null); + $userStatus->setCustomMessage(null); + $userStatus->setClearAt(null); + + if ($userStatus->getId() !== null) { + $this->mapper->update($userStatus); + return; + } + $this->mapper->insert($userStatus); + } + + /** + * @param string $userId * @param string|null $statusIcon * @param string $message * @param int|null $clearAt |