Fix:Users table activity & cleanup

This commit is contained in:
advplyr 2022-11-24 14:44:09 -06:00
parent 47e732c213
commit 42e68edc65
3 changed files with 18 additions and 23 deletions

View File

@ -26,11 +26,9 @@
</td> </td>
<td class="text-sm">{{ user.type }}</td> <td class="text-sm">{{ user.type }}</td>
<td class="hidden lg:table-cell"> <td class="hidden lg:table-cell">
<div v-if="usersOnline[user.id] && usersOnline[user.id].session && usersOnline[user.id].session.libraryItem && usersOnline[user.id].session.libraryItem.media"> <div v-if="usersOnline[user.id]">
<p class="truncate text-xs">Listening: {{ usersOnline[user.id].session.libraryItem.media.metadata.title || '' }}</p> <p v-if="usersOnline[user.id].session && usersOnline[user.id].session.libraryItem" class="truncate text-xs">Listening: {{ usersOnline[user.id].session.libraryItem.media.metadata.title || '' }}</p>
</div> <p v-else-if="usersOnline[user.id].mostRecent && usersOnline[user.id].mostRecent.media" class="truncate text-xs">Last: {{ usersOnline[user.id].mostRecent.media.metadata.title }}</p>
<div v-else-if="user.mostRecent">
<p class="truncate text-xs">Last: {{ user.mostRecent.metadata.title }}</p>
</div> </div>
</td> </td>
<td class="text-xs font-mono hidden sm:table-cell"> <td class="text-xs font-mono hidden sm:table-cell">
@ -81,7 +79,7 @@ export default {
}, },
usersOnline() { usersOnline() {
var usermap = {} var usermap = {}
this.$store.state.users.users.forEach((u) => (usermap[u.id] = { online: true, session: u.session })) this.$store.state.users.usersOnline.forEach((u) => (usermap[u.id] = u))
return usermap return usermap
} }
}, },

View File

@ -133,10 +133,7 @@ export default {
}) })
if (payload.usersOnline) { if (payload.usersOnline) {
this.$store.commit('users/resetUsers') this.$store.commit('users/setUsersOnline', payload.usersOnline)
payload.usersOnline.forEach((user) => {
this.$store.commit('users/updateUser', user)
})
} }
this.$eventBus.$emit('socket_init') this.$eventBus.$emit('socket_init')
@ -283,13 +280,13 @@ export default {
} }
}, },
userOnline(user) { userOnline(user) {
this.$store.commit('users/updateUser', user) this.$store.commit('users/updateUserOnline', user)
}, },
userOffline(user) { userOffline(user) {
this.$store.commit('users/removeUser', user) this.$store.commit('users/removeUserOnline', user)
}, },
userStreamUpdate(user) { userStreamUpdate(user) {
this.$store.commit('users/updateUser', user) this.$store.commit('users/updateUserOnline', user)
}, },
userMediaProgressUpdate(payload) { userMediaProgressUpdate(payload) {
this.$store.commit('user/updateMediaProgress', payload) this.$store.commit('user/updateMediaProgress', payload)

View File

@ -1,11 +1,11 @@
export const state = () => ({ export const state = () => ({
users: [] usersOnline: []
}) })
export const getters = { export const getters = {
getIsUserOnline: state => id => { getIsUserOnline: state => id => {
return state.users.find(u => u.id === id) return state.usersOnline.find(u => u.id === id)
} }
} }
@ -14,18 +14,18 @@ export const actions = {
} }
export const mutations = { export const mutations = {
resetUsers(state) { setUsersOnline(state, usersOnline) {
state.users = [] state.usersOnline = usersOnline
}, },
updateUser(state, user) { updateUserOnline(state, user) {
var index = state.users.findIndex(u => u.id === user.id) var index = state.usersOnline.findIndex(u => u.id === user.id)
if (index >= 0) { if (index >= 0) {
state.users.splice(index, 1, user) state.usersOnline.splice(index, 1, user)
} else { } else {
state.users.push(user) state.usersOnline.push(user)
} }
}, },
removeUser(state, user) { removeUserOnline(state, user) {
state.users = state.users.filter(u => u.id !== user.id) state.usersOnline = state.usersOnline.filter(u => u.id !== user.id)
} }
} }