summaryrefslogtreecommitdiffstats
path: root/apps/user_status/src
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-06-16 11:14:00 +0200
committerJoas Schilling <coding@schilljs.com>2021-06-16 11:32:32 +0200
commit38d2f978a6d720b7bbeab70fe7841d13e206a740 (patch)
treecad567fb9de665d5d8e01de1187085b08753f629 /apps/user_status/src
parent0a9a5f006a94645d409748bf56b818c87e496e75 (diff)
downloadnextcloud-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.vue9
-rw-r--r--apps/user_status/src/services/heartbeatService.js3
-rw-r--r--apps/user_status/src/store/userStatus.js19
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