diff --git a/apps/user_status/appinfo/routes.php b/apps/user_status/appinfo/routes.php index 147d1927358d6..fe534098a5887 100644 --- a/apps/user_status/appinfo/routes.php +++ b/apps/user_status/appinfo/routes.php @@ -34,6 +34,7 @@ ['name' => 'UserStatus#setPredefinedMessage', 'url' => '/api/v1/user_status/message/predefined', 'verb' => 'PUT'], ['name' => 'UserStatus#setCustomMessage', 'url' => '/api/v1/user_status/message/custom', 'verb' => 'PUT'], ['name' => 'UserStatus#clearMessage', 'url' => '/api/v1/user_status/message', 'verb' => 'DELETE'], + ['name' => 'UserStatus#revertStatus', 'url' => '/api/v1/user_status/revert/{messageId}', 'verb' => 'DELETE'], // Routes for listing default routes ['name' => 'PredefinedStatus#findAll', 'url' => '/api/v1/predefined_statuses/', 'verb' => 'GET'], // Route for doing heartbeats diff --git a/apps/user_status/lib/Capabilities.php b/apps/user_status/lib/Capabilities.php index 8f26525286c59..5b3e105d31ad8 100644 --- a/apps/user_status/lib/Capabilities.php +++ b/apps/user_status/lib/Capabilities.php @@ -47,6 +47,7 @@ public function getCapabilities() { return [ 'user_status' => [ 'enabled' => true, + 'restore' => true, 'supports_emoji' => $this->emojiHelper->doesPlatformSupportEmoji(), ], ]; diff --git a/apps/user_status/lib/Controller/UserStatusController.php b/apps/user_status/lib/Controller/UserStatusController.php index 214dc21f453d0..aded923d07fa5 100644 --- a/apps/user_status/lib/Controller/UserStatusController.php +++ b/apps/user_status/lib/Controller/UserStatusController.php @@ -184,6 +184,19 @@ public function clearMessage(): DataResponse { return new DataResponse([]); } + /** + * @NoAdminRequired + * + * @return DataResponse + */ + public function revertStatus(string $messageId): DataResponse { + $backupStatus = $this->service->revertUserStatus($this->userId, $messageId, true); + if ($backupStatus) { + return new DataResponse($this->formatStatus($backupStatus)); + } + return new DataResponse([]); + } + /** * @param UserStatus $status * @return array diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php index 1b7b44d95d37b..b5dd3cd361a8f 100644 --- a/apps/user_status/lib/Service/StatusService.php +++ b/apps/user_status/lib/Service/StatusService.php @@ -496,25 +496,32 @@ public function backupCurrentStatus(string $userId): bool { } } - public function revertUserStatus(string $userId, string $messageId): void { + public function revertUserStatus(string $userId, string $messageId, bool $revertedManually = false): ?UserStatus { try { /** @var UserStatus $userStatus */ $backupUserStatus = $this->mapper->findByUserId($userId, true); } catch (DoesNotExistException $ex) { // No user status to revert, do nothing - return; + return null; } $deleted = $this->mapper->deleteCurrentStatusToRestoreBackup($userId, $messageId); if (!$deleted) { // Another status is set automatically or no status, do nothing - return; + return null; + } + + if ($revertedManually && $backupUserStatus->getStatus() === IUserStatus::OFFLINE) { + // When the user reverts the status manually they are online + $backupUserStatus->setStatus(IUserStatus::ONLINE); } $backupUserStatus->setIsBackup(false); // Remove the underscore prefix added when creating the backup $backupUserStatus->setUserId(substr($backupUserStatus->getUserId(), 1)); $this->mapper->update($backupUserStatus); + + return $backupUserStatus; } public function revertMultipleUserStatus(array $userIds, string $messageId): void { diff --git a/apps/user_status/src/components/PredefinedStatus.vue b/apps/user_status/src/components/PredefinedStatus.vue index b5eafaed30bb5..2775051439c01 100644 --- a/apps/user_status/src/components/PredefinedStatus.vue +++ b/apps/user_status/src/components/PredefinedStatus.vue @@ -104,7 +104,7 @@ export default { } &__clear-at { - opacity: .7; + color: var(--color-text-maxcontrast); &::before { content: ' – '; diff --git a/apps/user_status/src/components/PredefinedStatusesList.vue b/apps/user_status/src/components/PredefinedStatusesList.vue index 6d62eee8b0c13..a3ac3c6867765 100644 --- a/apps/user_status/src/components/PredefinedStatusesList.vue +++ b/apps/user_status/src/components/PredefinedStatusesList.vue @@ -20,7 +20,7 @@ -->