Skip to content

Commit

Permalink
Merge pull request #22801 from nextcloud/bugfix/noid/status_event_bus
Browse files Browse the repository at this point in the history
Emit event on status-change
  • Loading branch information
rullzer authored Sep 14, 2020
2 parents 51320aa + f4d4975 commit 49f5ed0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
4 changes: 2 additions & 2 deletions apps/user_status/js/dashboard.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/user_status/js/dashboard.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/user_status/js/user-status-menu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/user_status/js/user-status-menu.js.map

Large diffs are not rendered by default.

42 changes: 38 additions & 4 deletions apps/user_status/src/store/userStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {
clearMessage,
} from '../services/statusService'
import { loadState } from '@nextcloud/initial-state'
import { getCurrentUser } from '@nextcloud/auth'
import { getTimestampForClearAt } from '../services/clearAtService'
import { emit } from '@nextcloud/event-bus'

const state = {
// Status (online / away / dnd / invisible / offline)
Expand Down Expand Up @@ -145,64 +147,96 @@ const actions = {
*
* @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function
* @param {Object} vuex.state The Vuex state object
* @param {Object} data The data destructuring object
* @param {String} data.statusType The new status type
* @returns {Promise<void>}
*/
async setStatus({ commit }, { statusType }) {
async setStatus({ commit, state }, { statusType }) {
await 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,
})
},

/**
* Sets a message using a predefined message
*
* @param {Object} vuex The Vuex destructuring object
* @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} data The data destructuring object
* @param {String} data.messageId The messageId
* @param {Object|null} data.clearAt When to automatically clear the status
* @returns {Promise<void>}
*/
async setPredefinedMessage({ commit, rootState }, { messageId, clearAt }) {
async setPredefinedMessage({ commit, rootState, state }, { messageId, clearAt }) {
const resolvedClearAt = getTimestampForClearAt(clearAt)

await setPredefinedMessage(messageId, resolvedClearAt)
const status = rootState.predefinedStatuses.predefinedStatuses.find((status) => status.id === messageId)
const { message, icon } = status

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,
})
},

/**
* Sets a custom message
*
* @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function
* @param {Object} vuex.state The Vuex state object
* @param {Object} data The data destructuring object
* @param {String} data.message The message
* @param {String} data.icon The icon
* @param {Object|null} data.clearAt When to automatically clear the status
* @returns {Promise<void>}
*/
async setCustomMessage({ commit }, { message, icon, clearAt }) {
async setCustomMessage({ commit, state }, { message, icon, clearAt }) {
const resolvedClearAt = getTimestampForClearAt(clearAt)

await setCustomMessage(message, icon, 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,
})
},

/**
* Clears the status
*
* @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function
* @param {Object} vuex.state The Vuex state object
* @returns {Promise<void>}
*/
async clearMessage({ commit }) {
async clearMessage({ commit, state }) {
await clearMessage()
commit('clearMessage')
emit('user_status:status.updated', {
status: state.status,
message: state.message,
icon: state.icon,
clearAt: state.clearAt,
userId: getCurrentUser()?.uid,
})
},

/**
Expand Down

0 comments on commit 49f5ed0

Please sign in to comment.