diff --git a/apps/user_status/appinfo/routes.php b/apps/user_status/appinfo/routes.php
index 147d1927358..fe534098a58 100644
--- a/apps/user_status/appinfo/routes.php
+++ b/apps/user_status/appinfo/routes.php
@@ -34,6 +34,7 @@ return [
['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/Controller/UserStatusController.php b/apps/user_status/lib/Controller/UserStatusController.php
index 214dc21f453..aded923d07f 100644
--- a/apps/user_status/lib/Controller/UserStatusController.php
+++ b/apps/user_status/lib/Controller/UserStatusController.php
@@ -184,6 +184,19 @@ class UserStatusController extends OCSController {
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 1b7b44d95d3..b5dd3cd361a 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -496,25 +496,32 @@ class StatusService {
}
}
- 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 b5eafaed30b..2775051439c 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/PreviousStatus.vue b/apps/user_status/src/components/PreviousStatus.vue
new file mode 100644
index 00000000000..6364277bdfb
--- /dev/null
+++ b/apps/user_status/src/components/PreviousStatus.vue
@@ -0,0 +1,120 @@
+
+
+
+
+ {{ icon }}
+
+
+ {{ message }}
+
+
+ {{ $t('user_status', 'Previously set') }}
+
+
+
+
+ {{ $t('user_status', 'Reset status') }}
+
+
+
+
+
+
+
+
diff --git a/apps/user_status/src/components/SetStatusModal.vue b/apps/user_status/src/components/SetStatusModal.vue
index c3f0a793df3..f4b528a5a92 100644
--- a/apps/user_status/src/components/SetStatusModal.vue
+++ b/apps/user_status/src/components/SetStatusModal.vue
@@ -48,6 +48,14 @@
@submit="saveStatus"
@select-icon="setIcon" />
+
+ {{ $t('user_status', 'Your status was set automatically') }}
+
+
@@ -78,6 +86,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import { getAllStatusOptions } from '../services/statusOptionsService.js'
import OnlineStatusMixin from '../mixins/OnlineStatusMixin.js'
import PredefinedStatusesList from './PredefinedStatusesList.vue'
+import PreviousStatus from './PreviousStatus.vue'
import CustomMessageInput from './CustomMessageInput.vue'
import ClearAtSelect from './ClearAtSelect.vue'
import OnlineStatusSelect from './OnlineStatusSelect.vue'
@@ -91,6 +100,7 @@ export default {
NcModal,
OnlineStatusSelect,
PredefinedStatusesList,
+ PreviousStatus,
NcButton,
},
mixins: [OnlineStatusMixin],
@@ -98,21 +108,53 @@ export default {
data() {
return {
clearAt: null,
- icon: null,
- message: '',
- messageId: '',
isSavingStatus: false,
statuses: getAllStatusOptions(),
}
},
+ computed: {
+ messageId() {
+ return this.$store.state.userStatus.messageId
+ },
+ icon() {
+ return this.$store.state.userStatus.icon
+ },
+ message() {
+ return this.$store.state.userStatus.message || ''
+ },
+ backupIcon() {
+ return this.$store.state.userBackupStatus.icon || ''
+ },
+ backupMessage() {
+ return this.$store.state.userBackupStatus.message || ''
+ },
+
+ resetButtonText() {
+ if (this.backupIcon && this.backupMessage) {
+ return this.$t('user_status', 'Reset status to "{icon} {message}"', {
+ icon: this.backupIcon,
+ message: this.backupMessage,
+ })
+ } else if (this.backupMessage) {
+ return this.$t('user_status', 'Reset status to "{message}"', {
+ message: this.backupMessage,
+ })
+ } else if (this.backupIcon) {
+ return this.$t('user_status', 'Reset status to "{icon}"', {
+ icon: this.backupIcon,
+ })
+ }
+
+ return this.$t('user_status', 'Reset status')
+ },
+ },
+
/**
* Loads the current status when a user opens dialog
*/
mounted() {
- this.messageId = this.$store.state.userStatus.messageId
- this.icon = this.$store.state.userStatus.icon
- this.message = this.$store.state.userStatus.message || ''
+ this.$store.dispatch('fetchBackupFromServer')
if (this.$store.state.userStatus.clearAt !== null) {
this.clearAt = {
@@ -222,6 +264,26 @@ export default {
this.isSavingStatus = false
this.closeModal()
},
+ /**
+ *
+ * @return {Promise}
+ */
+ async revertBackupFromServer() {
+ try {
+ this.isSavingStatus = true
+
+ await this.$store.dispatch('revertBackupFromServer', {
+ messageId: this.messageId,
+ })
+ } catch (err) {
+ showError(this.$t('user_status', 'There was an error reverting the status'))
+ console.debug(err)
+ this.isSavingStatus = false
+ return
+ }
+
+ this.isSavingStatus = false
+ },
},
}
@@ -248,6 +310,13 @@ export default {
margin-bottom: 10px;
}
+ &__automation-hint {
+ display: flex;
+ width: 100%;
+ margin-bottom: 10px;
+ color: var(--color-text-maxcontrast);
+ }
+
.status-buttons {
display: flex;
padding: 3px;
diff --git a/apps/user_status/src/services/statusService.js b/apps/user_status/src/services/statusService.js
index f4bda930303..fb77866a4f4 100644
--- a/apps/user_status/src/services/statusService.js
+++ b/apps/user_status/src/services/statusService.js
@@ -35,6 +35,19 @@ const fetchCurrentStatus = async () => {
return response.data.ocs.data
}
+/**
+ * Fetches the current user-status
+ *
+ * @param {string} userId
+ * @return {Promise