From 17498ef906b79dd68276faa2a5624b90f3f0bc2b Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 24 Jun 2019 04:21:09 -0400 Subject: [PATCH] update favs and repeats stats using favoritedByUsers and rebloggedByUsers data --- src/modules/statuses.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index cf65c9f4..514f3081 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -492,10 +492,15 @@ export const mutations = { queueFlush (state, { timeline, id }) { state.timelines[timeline].flushMarker = id }, - addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers }) { + addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers, currentUser }) { const newStatus = state.allStatusesObject[id] newStatus.favoritedBy = favoritedByUsers.filter(_ => _) newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _) + // favorites and repeats stats can be incorrect based on polling condition, let's update them using the most recent data + newStatus.fave_num = newStatus.favoritedBy.length + newStatus.repeat_num = newStatus.rebloggedBy.length + newStatus.favorited = !!newStatus.favoritedBy.find(({ id }) => currentUser.id === id) + newStatus.repeated = !!newStatus.rebloggedBy.find(({ id }) => currentUser.id === id) }, updateStatusWithPoll (state, { id, poll }) { const status = state.allStatusesObject[id] @@ -582,7 +587,7 @@ const statuses = { rootState.api.backendInteractor.fetchFavoritedByUsers(id), rootState.api.backendInteractor.fetchRebloggedByUsers(id) ]).then(([favoritedByUsers, rebloggedByUsers]) => - commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers }) + commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers, currentUser: rootState.users.currentUser }) ) } },