diff options
author | Joas Schilling <coding@schilljs.com> | 2021-06-16 11:14:00 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-06-16 11:32:32 +0200 |
commit | 38d2f978a6d720b7bbeab70fe7841d13e206a740 (patch) | |
tree | cad567fb9de665d5d8e01de1187085b08753f629 /apps/user_status/src | |
parent | 0a9a5f006a94645d409748bf56b818c87e496e75 (diff) | |
download | nextcloud-server-38d2f978a6d720b7bbeab70fe7841d13e206a740.tar.gz nextcloud-server-38d2f978a6d720b7bbeab70fe7841d13e206a740.zip |
Save a request everytime we send the heartbeat
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_status/src')
-rw-r--r-- | apps/user_status/src/UserStatus.vue | 9 | ||||
-rw-r--r-- | apps/user_status/src/services/heartbeatService.js | 3 | ||||
-rw-r--r-- | apps/user_status/src/store/userStatus.js | 19 |
3 files changed, 27 insertions, 4 deletions
diff --git a/apps/user_status/src/UserStatus.vue b/apps/user_status/src/UserStatus.vue index 00501274b62..b92ff1dae8c 100644 --- a/apps/user_status/src/UserStatus.vue +++ b/apps/user_status/src/UserStatus.vue @@ -156,12 +156,15 @@ export default { */ async _backgroundHeartbeat() { try { - await sendHeartbeat(this.isAway) + const status = await sendHeartbeat(this.isAway) + if (status?.userId) { + this.$store.dispatch('setStatusFromHeartbeat', status) + } else { + await this.$store.dispatch('reFetchStatusFromServer') + } } catch (error) { console.debug('Failed sending heartbeat, got: ' + error.response.status) - return } - await this.$store.dispatch('reFetchStatusFromServer') }, }, } diff --git a/apps/user_status/src/services/heartbeatService.js b/apps/user_status/src/services/heartbeatService.js index ec3a0e76cc8..4a789a8a012 100644 --- a/apps/user_status/src/services/heartbeatService.js +++ b/apps/user_status/src/services/heartbeatService.js @@ -31,9 +31,10 @@ import { generateUrl } from '@nextcloud/router' */ const sendHeartbeat = async(isAway) => { const url = generateUrl('/apps/user_status/heartbeat') - await HttpClient.put(url, { + const response = await HttpClient.put(url, { status: isAway ? 'away' : 'online', }) + return response.data } export { diff --git a/apps/user_status/src/store/userStatus.js b/apps/user_status/src/store/userStatus.js index cde1b5a6f6e..4b2035bb6e4 100644 --- a/apps/user_status/src/store/userStatus.js +++ b/apps/user_status/src/store/userStatus.js @@ -253,6 +253,25 @@ const actions = { }, /** + * Stores the status we got in the reply of the heartbeat + * + * @param {Object} vuex The Vuex destructuring object + * @param {Function} vuex.commit The Vuex commit function + * @param {Object} status The data destructuring object + * @param {String} status.status The status type + * @param {Boolean} status.statusIsUserDefined Whether or not this status is user-defined + * @param {String} status.message The message + * @param {String} status.icon The icon + * @param {Number} status.clearAt When to automatically clear the status + * @param {Boolean} status.messageIsPredefined Whether or not the message is predefined + * @param {string} status.messageId The id of the predefined message + * @returns {Promise<void>} + */ + async setStatusFromHeartbeat({ commit }, status) { + commit('loadStatusFromServer', status) + }, + + /** * Loads the server from the initial state * * @param {Object} vuex The Vuex destructuring object |