Reset old mutes state after fetching new mutes data

This commit is contained in:
taehoon 2019-03-01 13:30:01 -05:00
parent 302310a653
commit 9b690209d0

View file

@ -102,10 +102,15 @@ export const mutations = {
} }
}) })
}, },
saveBlocks (state, blockIds) { saveBlockIds (state, blockIds) {
state.currentUser.blockIds = blockIds state.currentUser.blockIds = blockIds
}, },
saveMutes (state, muteIds) { updateMutes (state, mutedUsers) {
each(state.users, (user) => { user.muted = false })
const newUsers = map(mutedUsers, (user) => ({ ...user, muted: true }))
each(newUsers, (user) => mergeOrAdd(state.users, state.usersObject, user))
},
saveMuteIds (state, muteIds) {
state.currentUser.muteIds = muteIds state.currentUser.muteIds = muteIds
}, },
muteUser (state, id) { muteUser (state, id) {
@ -180,7 +185,7 @@ const users = {
fetchBlocks (store) { fetchBlocks (store) {
return store.rootState.api.backendInteractor.fetchBlocks() return store.rootState.api.backendInteractor.fetchBlocks()
.then((blocks) => { .then((blocks) => {
store.commit('saveBlocks', map(blocks, 'id')) store.commit('saveBlockIds', map(blocks, 'id'))
store.commit('addNewUsers', blocks) store.commit('addNewUsers', blocks)
return blocks return blocks
}) })
@ -205,11 +210,10 @@ const users = {
const promises = mutes.map(({ id }) => store.rootState.api.backendInteractor.fetchUser({ id })) const promises = mutes.map(({ id }) => store.rootState.api.backendInteractor.fetchUser({ id }))
return Promise.all(promises) return Promise.all(promises)
}) })
.then((mutedUsers) => { .then((mutes) => {
each(mutedUsers, (user) => { user.muted = true }) store.commit('updateMutes', mutes)
store.commit('addNewUsers', mutedUsers) store.commit('saveMuteIds', map(mutes, 'id'))
store.commit('saveMutes', map(mutedUsers, 'id')) return mutes
// TODO: Unset muted property of the rest users
}) })
}, },
muteUser (store, id) { muteUser (store, id) {