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 class="text-sm">{{ user.type }}</td>
<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">
<p class="truncate text-xs">Listening: {{ usersOnline[user.id].session.libraryItem.media.metadata.title || '' }}</p>
</div>
<div v-else-if="user.mostRecent">
<p class="truncate text-xs">Last: {{ user.mostRecent.metadata.title }}</p>
<div v-if="usersOnline[user.id]">
<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>
<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>
</td>
<td class="text-xs font-mono hidden sm:table-cell">
@ -81,7 +79,7 @@ export default {
},
usersOnline() {
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
}
},

View File

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

View File

@ -1,11 +1,11 @@
export const state = () => ({
users: []
usersOnline: []
})
export const getters = {
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 = {
resetUsers(state) {
state.users = []
setUsersOnline(state, usersOnline) {
state.usersOnline = usersOnline
},
updateUser(state, user) {
var index = state.users.findIndex(u => u.id === user.id)
updateUserOnline(state, user) {
var index = state.usersOnline.findIndex(u => u.id === user.id)
if (index >= 0) {
state.users.splice(index, 1, user)
state.usersOnline.splice(index, 1, user)
} else {
state.users.push(user)
state.usersOnline.push(user)
}
},
removeUser(state, user) {
state.users = state.users.filter(u => u.id !== user.id)
removeUserOnline(state, user) {
state.usersOnline = state.usersOnline.filter(u => u.id !== user.id)
}
}