Added logic to process reply to favorite request and update likes counter

accordingly. Should fix some of cases of doubled likes and likes counter not decrementing.
This commit is contained in:
Henry Jameson 2018-08-27 23:15:58 +03:00
parent fd604dfd2a
commit 226849b26e

View file

@ -225,7 +225,8 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
}, },
'favorite': (favorite) => { 'favorite': (favorite) => {
// Only update if this is a new favorite. // Only update if this is a new favorite.
if (!state.favorites.has(favorite.id)) { // Ignore our own favorites because we get info about likes as response to like request
if (!state.favorites.has(favorite.id) && user.id !== favorite.user.id) {
state.favorites.add(favorite.id) state.favorites.add(favorite.id)
favoriteStatus(favorite) favoriteStatus(favorite)
} }
@ -347,6 +348,11 @@ export const mutations = {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
newStatus.favorited = value newStatus.favorited = value
}, },
setFavoritedConfirm (state, { status }) {
const newStatus = state.allStatusesObject[status.id]
newStatus.favorited = status.favorited
newStatus.fave_num = status.fave_num
},
setRetweeted (state, { status, value }) { setRetweeted (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
newStatus.repeated = value newStatus.repeated = value
@ -424,11 +430,31 @@ const statuses = {
// Optimistic favoriting... // Optimistic favoriting...
commit('setFavorited', { status, value: true }) commit('setFavorited', { status, value: true })
apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
.then(response => {
if (response.ok) {
return response.json()
} else {
return {}
}
})
.then(status => {
commit('setFavoritedConfirm', { status })
})
}, },
unfavorite ({ rootState, commit }, status) { unfavorite ({ rootState, commit }, status) {
// Optimistic favoriting... // Optimistic favoriting...
commit('setFavorited', { status, value: false }) commit('setFavorited', { status, value: false })
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
.then(response => {
if (response.ok) {
return response.json()
} else {
return {}
}
})
.then(status => {
commit('setFavoritedConfirm', { status })
})
}, },
retweet ({ rootState, commit }, status) { retweet ({ rootState, commit }, status) {
// Optimistic retweeting... // Optimistic retweeting...