Merge pull request #22801 from nextcloud/bugfix/noid/status_event_bus

Emit event on status-change
This commit is contained in:
Roeland Jago Douma 2020-09-14 20:40:32 +02:00 committed by GitHub
commit 49f5ed01ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 10 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -27,7 +27,9 @@ import {
clearMessage, clearMessage,
} from '../services/statusService' } from '../services/statusService'
import { loadState } from '@nextcloud/initial-state' import { loadState } from '@nextcloud/initial-state'
import { getCurrentUser } from '@nextcloud/auth'
import { getTimestampForClearAt } from '../services/clearAtService' import { getTimestampForClearAt } from '../services/clearAtService'
import { emit } from '@nextcloud/event-bus'
const state = { const state = {
// Status (online / away / dnd / invisible / offline) // Status (online / away / dnd / invisible / offline)
@ -145,13 +147,21 @@ const actions = {
* *
* @param {Object} vuex The Vuex destructuring object * @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function * @param {Function} vuex.commit The Vuex commit function
* @param {Object} vuex.state The Vuex state object
* @param {Object} data The data destructuring object * @param {Object} data The data destructuring object
* @param {String} data.statusType The new status type * @param {String} data.statusType The new status type
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async setStatus({ commit }, { statusType }) { async setStatus({ commit, state }, { statusType }) {
await setStatus(statusType) await setStatus(statusType)
commit('setStatus', { statusType }) commit('setStatus', { statusType })
emit('user_status:status.updated', {
status: state.status,
message: state.message,
icon: state.icon,
clearAt: state.clearAt,
userId: getCurrentUser()?.uid,
})
}, },
/** /**
@ -159,13 +169,14 @@ const actions = {
* *
* @param {Object} vuex The Vuex destructuring object * @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function * @param {Function} vuex.commit The Vuex commit function
* @param {Object} vuex.state The Vuex state object
* @param {Object} vuex.rootState The Vuex root state * @param {Object} vuex.rootState The Vuex root state
* @param {Object} data The data destructuring object * @param {Object} data The data destructuring object
* @param {String} data.messageId The messageId * @param {String} data.messageId The messageId
* @param {Object|null} data.clearAt When to automatically clear the status * @param {Object|null} data.clearAt When to automatically clear the status
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async setPredefinedMessage({ commit, rootState }, { messageId, clearAt }) { async setPredefinedMessage({ commit, rootState, state }, { messageId, clearAt }) {
const resolvedClearAt = getTimestampForClearAt(clearAt) const resolvedClearAt = getTimestampForClearAt(clearAt)
await setPredefinedMessage(messageId, resolvedClearAt) await setPredefinedMessage(messageId, resolvedClearAt)
@ -173,6 +184,13 @@ const actions = {
const { message, icon } = status const { message, icon } = status
commit('setPredefinedMessage', { messageId, clearAt: resolvedClearAt, message, icon }) commit('setPredefinedMessage', { messageId, clearAt: resolvedClearAt, message, icon })
emit('user_status:status.updated', {
status: state.status,
message: state.message,
icon: state.icon,
clearAt: state.clearAt,
userId: getCurrentUser()?.uid,
})
}, },
/** /**
@ -180,17 +198,25 @@ const actions = {
* *
* @param {Object} vuex The Vuex destructuring object * @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function * @param {Function} vuex.commit The Vuex commit function
* @param {Object} vuex.state The Vuex state object
* @param {Object} data The data destructuring object * @param {Object} data The data destructuring object
* @param {String} data.message The message * @param {String} data.message The message
* @param {String} data.icon The icon * @param {String} data.icon The icon
* @param {Object|null} data.clearAt When to automatically clear the status * @param {Object|null} data.clearAt When to automatically clear the status
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async setCustomMessage({ commit }, { message, icon, clearAt }) { async setCustomMessage({ commit, state }, { message, icon, clearAt }) {
const resolvedClearAt = getTimestampForClearAt(clearAt) const resolvedClearAt = getTimestampForClearAt(clearAt)
await setCustomMessage(message, icon, resolvedClearAt) await setCustomMessage(message, icon, resolvedClearAt)
commit('setCustomMessage', { message, icon, clearAt: resolvedClearAt }) commit('setCustomMessage', { message, icon, clearAt: resolvedClearAt })
emit('user_status:status.updated', {
status: state.status,
message: state.message,
icon: state.icon,
clearAt: state.clearAt,
userId: getCurrentUser()?.uid,
})
}, },
/** /**
@ -198,11 +224,19 @@ const actions = {
* *
* @param {Object} vuex The Vuex destructuring object * @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function * @param {Function} vuex.commit The Vuex commit function
* @param {Object} vuex.state The Vuex state object
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async clearMessage({ commit }) { async clearMessage({ commit, state }) {
await clearMessage() await clearMessage()
commit('clearMessage') commit('clearMessage')
emit('user_status:status.updated', {
status: state.status,
message: state.message,
icon: state.icon,
clearAt: state.clearAt,
userId: getCurrentUser()?.uid,
})
}, },
/** /**