From 1429a9a8ef9c65493e0c9276c4cc5f8b8cf94bc2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 27 May 2022 11:28:59 +0200 Subject: Also reset the status on clearAt When you set yourself to "DND - In a meeting" for one hour, the expectation is that you are also "online"/normal again when the meeting is over. So we extend the logic to also include the status itself to be reverted. Signed-off-by: Joas Schilling --- .../lib/BackgroundJob/ClearOldStatusesBackgroundJob.php | 2 +- .../user_status/lib/Controller/UserStatusController.php | 4 ++-- apps/user_status/lib/Db/UserStatusMapper.php | 8 ++------ apps/user_status/lib/Service/StatusService.php | 7 ++++--- apps/user_status/src/components/ClearAtSelect.vue | 2 +- .../BackgroundJob/ClearOldStatusesBackgroundJobTest.php | 2 +- .../tests/Unit/Controller/UserStatusControllerTest.php | 3 ++- apps/user_status/tests/Unit/Db/UserStatusMapperTest.php | 17 ++++++----------- 8 files changed, 19 insertions(+), 26 deletions(-) (limited to 'apps/user_status') diff --git a/apps/user_status/lib/BackgroundJob/ClearOldStatusesBackgroundJob.php b/apps/user_status/lib/BackgroundJob/ClearOldStatusesBackgroundJob.php index 0d8f5ac431b..8f2ef421597 100644 --- a/apps/user_status/lib/BackgroundJob/ClearOldStatusesBackgroundJob.php +++ b/apps/user_status/lib/BackgroundJob/ClearOldStatusesBackgroundJob.php @@ -61,7 +61,7 @@ class ClearOldStatusesBackgroundJob extends TimedJob { protected function run($argument) { $now = $this->time->getTime(); - $this->mapper->clearMessagesOlderThan($now); + $this->mapper->clearOlderThanClearAt($now); $this->mapper->clearStatusesOlderThan($now - StatusService::INVALIDATE_STATUS_THRESHOLD, $now); } } diff --git a/apps/user_status/lib/Controller/UserStatusController.php b/apps/user_status/lib/Controller/UserStatusController.php index 8708a7c2aac..214dc21f453 100644 --- a/apps/user_status/lib/Controller/UserStatusController.php +++ b/apps/user_status/lib/Controller/UserStatusController.php @@ -135,7 +135,7 @@ class UserStatusController extends OCSController { * @NoAdminRequired * * @param string|null $statusIcon - * @param string $message + * @param string|null $message * @param int|null $clearAt * @return DataResponse * @throws OCSBadRequestException @@ -144,7 +144,7 @@ class UserStatusController extends OCSController { ?string $message, ?int $clearAt): DataResponse { try { - if ($message !== null && $message !== '') { + if (($message !== null && $message !== '') || ($clearAt !== null && $clearAt !== 0)) { $status = $this->service->setCustomMessage($this->userId, $statusIcon, $message, $clearAt); } else { $this->service->clearMessage($this->userId); diff --git a/apps/user_status/lib/Db/UserStatusMapper.php b/apps/user_status/lib/Db/UserStatusMapper.php index f67cfcd472d..10939116a53 100644 --- a/apps/user_status/lib/Db/UserStatusMapper.php +++ b/apps/user_status/lib/Db/UserStatusMapper.php @@ -145,13 +145,9 @@ class UserStatusMapper extends QBMapper { * * @param int $timestamp */ - public function clearMessagesOlderThan(int $timestamp): void { + public function clearOlderThanClearAt(int $timestamp): void { $qb = $this->db->getQueryBuilder(); - $qb->update($this->tableName) - ->set('message_id', $qb->createNamedParameter(null)) - ->set('custom_icon', $qb->createNamedParameter(null)) - ->set('custom_message', $qb->createNamedParameter(null)) - ->set('clear_at', $qb->createNamedParameter(null)) + $qb->delete($this->tableName) ->where($qb->expr()->isNotNull('clear_at')) ->andWhere($qb->expr()->lte('clear_at', $qb->createNamedParameter($timestamp, IQueryBuilder::PARAM_INT))); diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php index 9bf448d9de8..858db48f31f 100644 --- a/apps/user_status/lib/Service/StatusService.php +++ b/apps/user_status/lib/Service/StatusService.php @@ -302,7 +302,7 @@ class StatusService { /** * @param string $userId * @param string|null $statusIcon - * @param string $message + * @param string|null $message * @param int|null $clearAt * @return UserStatus * @throws InvalidClearAtException @@ -311,7 +311,7 @@ class StatusService { */ public function setCustomMessage(string $userId, ?string $statusIcon, - string $message, + ?string $message, ?int $clearAt): UserStatus { try { $userStatus = $this->mapper->findByUserId($userId); @@ -328,7 +328,7 @@ class StatusService { throw new InvalidStatusIconException('Status-Icon is longer than one character'); } // Check for maximum length of custom message - if (\mb_strlen($message) > self::MAXIMUM_MESSAGE_LENGTH) { + if ($message !== null && \mb_strlen($message) > self::MAXIMUM_MESSAGE_LENGTH) { throw new StatusMessageTooLongException('Message is longer than supported length of ' . self::MAXIMUM_MESSAGE_LENGTH . ' characters'); } // Check that clearAt is in the future @@ -432,6 +432,7 @@ class StatusService { $this->cleanStatus($status); } if ($clearAt !== null && $clearAt < $this->timeFactory->getTime()) { + $this->cleanStatus($status); $this->cleanStatusMessage($status); } if ($status->getMessageId() !== null) { diff --git a/apps/user_status/src/components/ClearAtSelect.vue b/apps/user_status/src/components/ClearAtSelect.vue index 09e0068f87f..d0a88ea8255 100644 --- a/apps/user_status/src/components/ClearAtSelect.vue +++ b/apps/user_status/src/components/ClearAtSelect.vue @@ -22,7 +22,7 @@