Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit event on status-change #22801

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we add the user, we could use the same event for other user status-updates as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, let me add that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristophWurst you approved this event name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the issue? the .?

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