audiobookshelf/client/store/users.js

31 lines
649 B
JavaScript
Raw Permalink Normal View History

export const state = () => ({
2022-11-24 21:44:09 +01:00
usersOnline: []
})
export const getters = {
getIsUserOnline: state => id => {
2022-11-24 21:44:09 +01:00
return state.usersOnline.find(u => u.id === id)
}
}
export const actions = {
}
export const mutations = {
2022-11-24 21:44:09 +01:00
setUsersOnline(state, usersOnline) {
state.usersOnline = usersOnline
},
2022-11-24 21:44:09 +01:00
updateUserOnline(state, user) {
var index = state.usersOnline.findIndex(u => u.id === user.id)
if (index >= 0) {
2022-11-24 21:44:09 +01:00
state.usersOnline.splice(index, 1, user)
} else {
2022-11-24 21:44:09 +01:00
state.usersOnline.push(user)
}
},
2022-11-24 21:44:09 +01:00
removeUserOnline(state, user) {
state.usersOnline = state.usersOnline.filter(u => u.id !== user.id)
}
}