mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
feat(user_status): Allow to manually revert an automated status
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
1a255379e8
commit
64776ff042
10 changed files with 369 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ export default {
|
|||
}
|
||||
|
||||
&__clear-at {
|
||||
opacity: .7;
|
||||
color: var(--color-text-maxcontrast);
|
||||
|
||||
&::before {
|
||||
content: ' – ';
|
||||
|
|
|
|||
120
apps/user_status/src/components/PreviousStatus.vue
Normal file
120
apps/user_status/src/components/PreviousStatus.vue
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<!--
|
||||
- @copyright Copyright (c) 2020 Georg Ehrke <oc.list@georgehrke.com>
|
||||
- @author Georg Ehrke <oc.list@georgehrke.com>
|
||||
-
|
||||
- @license GNU AGPL version 3 or any later version
|
||||
-
|
||||
- This program is free software: you can redistribute it and/or modify
|
||||
- it under the terms of the GNU Affero General Public License as
|
||||
- published by the Free Software Foundation, either version 3 of the
|
||||
- License, or (at your option) any later version.
|
||||
-
|
||||
- This program is distributed in the hope that it will be useful,
|
||||
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
- GNU Affero General Public License for more details.
|
||||
-
|
||||
- You should have received a copy of the GNU Affero General Public License
|
||||
- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-
|
||||
-->
|
||||
<template>
|
||||
<div class="predefined-status backup-status"
|
||||
tabindex="0"
|
||||
@keyup.enter="select"
|
||||
@keyup.space="select"
|
||||
@click="select">
|
||||
<span class="predefined-status__icon">
|
||||
{{ icon }}
|
||||
</span>
|
||||
<span class="predefined-status__message">
|
||||
{{ message }}
|
||||
</span>
|
||||
<span class="predefined-status__clear-at">
|
||||
{{ $t('user_status', 'Previously set') }}
|
||||
</span>
|
||||
|
||||
<div class="backup-status__reset-button">
|
||||
<NcButton @click="select">
|
||||
{{ $t('user_status', 'Reset status') }}
|
||||
</NcButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
|
||||
|
||||
export default {
|
||||
name: 'PreviousStatus',
|
||||
|
||||
components: {
|
||||
NcButton,
|
||||
},
|
||||
|
||||
props: {
|
||||
icon: {
|
||||
type: [String, null],
|
||||
required: true,
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* Emits an event when the user clicks the row
|
||||
*/
|
||||
select() {
|
||||
this.$emit('select')
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.predefined-status {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: flex-start;
|
||||
flex-basis: 100%;
|
||||
border-radius: var(--border-radius);
|
||||
align-items: center;
|
||||
min-height: 44px;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
background-color: var(--color-background-hover);
|
||||
}
|
||||
|
||||
&:active{
|
||||
background-color: var(--color-background-dark);
|
||||
}
|
||||
|
||||
&__icon {
|
||||
flex-basis: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&__message {
|
||||
font-weight: bold;
|
||||
padding: 0 6px;
|
||||
}
|
||||
|
||||
&__clear-at {
|
||||
color: var(--color-text-maxcontrast);
|
||||
|
||||
&::before {
|
||||
content: ' – ';
|
||||
}
|
||||
}
|
||||
}
|
||||
.backup-status {
|
||||
&__reset-button {
|
||||
justify-content: flex-end;
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -48,6 +48,14 @@
|
|||
@submit="saveStatus"
|
||||
@select-icon="setIcon" />
|
||||
</div>
|
||||
<div v-if="messageId"
|
||||
class="set-status-modal__automation-hint">
|
||||
{{ $t('user_status', 'Your status was set automatically') }}
|
||||
</div>
|
||||
<PreviousStatus v-if="messageId"
|
||||
:icon="backupIcon"
|
||||
:message="backupMessage"
|
||||
@select="revertBackupFromServer" />
|
||||
<PredefinedStatusesList @select-status="selectPredefinedMessage" />
|
||||
<ClearAtSelect :clear-at="clearAt"
|
||||
@select-clear-at="setClearAt" />
|
||||
|
|
@ -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<void>}
|
||||
*/
|
||||
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
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,19 @@ const fetchCurrentStatus = async () => {
|
|||
return response.data.ocs.data
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current user-status
|
||||
*
|
||||
* @param {string} userId
|
||||
* @return {Promise<object>}
|
||||
*/
|
||||
const fetchBackupStatus = async (userId) => {
|
||||
const url = generateOcsUrl('apps/user_status/api/v1/statuses/{userId}', { userId: '_' + userId })
|
||||
const response = await HttpClient.get(url)
|
||||
|
||||
return response.data.ocs.data
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status
|
||||
*
|
||||
|
|
@ -90,10 +103,25 @@ const clearMessage = async () => {
|
|||
await HttpClient.delete(url)
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert the automated status
|
||||
*
|
||||
* @param {string} messageId
|
||||
* @return {Promise<object>}
|
||||
*/
|
||||
const revertToBackupStatus = async (messageId) => {
|
||||
const url = generateOcsUrl('apps/user_status/api/v1/user_status/revert/{messageId}', { messageId })
|
||||
const response = await HttpClient.delete(url)
|
||||
|
||||
return response.data.ocs.data
|
||||
}
|
||||
|
||||
export {
|
||||
fetchCurrentStatus,
|
||||
fetchBackupStatus,
|
||||
setStatus,
|
||||
setCustomMessage,
|
||||
setPredefinedMessage,
|
||||
clearMessage,
|
||||
revertToBackupStatus,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import Vue from 'vue'
|
|||
import Vuex, { Store } from 'vuex'
|
||||
import predefinedStatuses from './predefinedStatuses.js'
|
||||
import userStatus from './userStatus.js'
|
||||
import userBackupStatus from './userBackupStatus.js'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
|
|
@ -31,6 +32,7 @@ export default new Store({
|
|||
modules: {
|
||||
predefinedStatuses,
|
||||
userStatus,
|
||||
userBackupStatus,
|
||||
},
|
||||
strict: true,
|
||||
})
|
||||
|
|
|
|||
117
apps/user_status/src/store/userBackupStatus.js
Normal file
117
apps/user_status/src/store/userBackupStatus.js
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* @copyright Copyright (c) 2020 Georg Ehrke
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Georg Ehrke <oc.list@georgehrke.com>
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import {
|
||||
fetchBackupStatus,
|
||||
revertToBackupStatus,
|
||||
} from '../services/statusService.js'
|
||||
import { getCurrentUser } from '@nextcloud/auth'
|
||||
import { emit } from '@nextcloud/event-bus'
|
||||
|
||||
const state = {
|
||||
// Status (online / away / dnd / invisible / offline)
|
||||
status: null,
|
||||
// Whether the status is user-defined
|
||||
statusIsUserDefined: null,
|
||||
// A custom message set by the user
|
||||
message: null,
|
||||
// The icon selected by the user
|
||||
icon: null,
|
||||
// When to automatically clean the status
|
||||
clearAt: null,
|
||||
// Whether the message is predefined
|
||||
// (and can automatically be translated by Nextcloud)
|
||||
messageIsPredefined: null,
|
||||
// The id of the message in case it's predefined
|
||||
messageId: null,
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
/**
|
||||
* Loads the status from initial state
|
||||
*
|
||||
* @param {object} state The Vuex state
|
||||
* @param {object} data The destructuring object
|
||||
* @param {string} data.status The status type
|
||||
* @param {boolean} data.statusIsUserDefined Whether or not this status is user-defined
|
||||
* @param {string} data.message The message
|
||||
* @param {string} data.icon The icon
|
||||
* @param {number} data.clearAt When to automatically clear the status
|
||||
* @param {boolean} data.messageIsPredefined Whether or not the message is predefined
|
||||
* @param {string} data.messageId The id of the predefined message
|
||||
*/
|
||||
loadBackupStatusFromServer(state, { status, statusIsUserDefined, message, icon, clearAt, messageIsPredefined, messageId }) {
|
||||
state.status = status
|
||||
state.message = message
|
||||
state.icon = icon
|
||||
|
||||
// Don't overwrite certain values if the refreshing comes in via short updates
|
||||
// E.g. from talk participant list which only has the status, message and icon
|
||||
if (typeof statusIsUserDefined !== 'undefined') {
|
||||
state.statusIsUserDefined = statusIsUserDefined
|
||||
}
|
||||
if (typeof clearAt !== 'undefined') {
|
||||
state.clearAt = clearAt
|
||||
}
|
||||
if (typeof messageIsPredefined !== 'undefined') {
|
||||
state.messageIsPredefined = messageIsPredefined
|
||||
}
|
||||
if (typeof messageId !== 'undefined') {
|
||||
state.messageId = messageId
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
const getters = {}
|
||||
|
||||
const actions = {
|
||||
/**
|
||||
* Re-fetches the status from the server
|
||||
*
|
||||
* @param {object} vuex The Vuex destructuring object
|
||||
* @param {Function} vuex.commit The Vuex commit function
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
async fetchBackupFromServer({ commit }) {
|
||||
const status = await fetchBackupStatus(getCurrentUser()?.uid)
|
||||
commit('loadBackupStatusFromServer', status)
|
||||
},
|
||||
|
||||
async revertBackupFromServer({ commit }, { messageId }) {
|
||||
const status = await revertToBackupStatus(messageId)
|
||||
if (status) {
|
||||
commit('loadBackupStatusFromServer', {})
|
||||
commit('loadStatusFromServer', status)
|
||||
emit('user_status:status.updated', {
|
||||
status: status.status,
|
||||
message: status.message,
|
||||
icon: status.icon,
|
||||
clearAt: status.clearAt,
|
||||
userId: getCurrentUser()?.uid,
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default { state, mutations, getters, actions }
|
||||
|
|
@ -35,7 +35,7 @@ import { emit } from '@nextcloud/event-bus'
|
|||
const state = {
|
||||
// Status (online / away / dnd / invisible / offline)
|
||||
status: null,
|
||||
// Whether or not the status is user-defined
|
||||
// Whether the status is user-defined
|
||||
statusIsUserDefined: null,
|
||||
// A custom message set by the user
|
||||
message: null,
|
||||
|
|
@ -43,7 +43,7 @@ const state = {
|
|||
icon: null,
|
||||
// When to automatically clean the status
|
||||
clearAt: null,
|
||||
// Whether or not the message is predefined
|
||||
// Whether the message is predefined
|
||||
// (and can automatically be translated by Nextcloud)
|
||||
messageIsPredefined: null,
|
||||
// The id of the message in case it's predefined
|
||||
|
|
|
|||
Loading…
Reference in a new issue