From ab4d7d9616319778b7ed5d79ca1f389c9e439113 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 27 Jun 2019 08:14:54 -0400 Subject: [PATCH] refetch favs and repeats separately --- src/components/status/status.js | 7 ++----- src/modules/statuses.js | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/components/status/status.js b/src/components/status/status.js index 6f83dbe0..284c657c 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -402,9 +402,6 @@ const Status = { setMedia () { const attachments = this.attachmentSize === 'hide' ? this.status.attachments : this.galleryAttachments return () => this.$store.dispatch('setMedia', attachments) - }, - refetchFavsAndRepeats () { - this.$store.dispatch('fetchFavsAndRepeats', this.status.id) } }, watch: { @@ -425,12 +422,12 @@ const Status = { }, 'status.repeat_num': function (num) { if (this.isFocused && this.statusFromGlobalRepository.rebloggedBy && this.statusFromGlobalRepository.rebloggedBy.length !== num) { - this.refetchFavsAndRepeats() + this.$store.dispatch('fetchRepeats', this.status.id) } }, 'status.fave_num': function (num) { if (this.isFocused && this.statusFromGlobalRepository.favoritedBy && this.statusFromGlobalRepository.favoritedBy.length !== num) { - this.refetchFavsAndRepeats() + this.$store.dispatch('fetchFavs', this.status.id) } } }, diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 514f3081..9d8d768c 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -492,15 +492,19 @@ export const mutations = { queueFlush (state, { timeline, id }) { state.timelines[timeline].flushMarker = id }, - addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers, currentUser }) { + addRepeats (state, { id, rebloggedByUsers, currentUser }) { + const newStatus = state.allStatusesObject[id] + newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _) + // repeats stats can be incorrect based on polling condition, let's update them using the most recent data + newStatus.repeat_num = newStatus.rebloggedBy.length + newStatus.repeated = !!newStatus.rebloggedBy.find(({ id }) => currentUser.id === id) + }, + addFavs (state, { id, favoritedByUsers, 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 + // favorites 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] @@ -586,9 +590,18 @@ const statuses = { Promise.all([ rootState.api.backendInteractor.fetchFavoritedByUsers(id), rootState.api.backendInteractor.fetchRebloggedByUsers(id) - ]).then(([favoritedByUsers, rebloggedByUsers]) => - commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers, currentUser: rootState.users.currentUser }) - ) + ]).then(([favoritedByUsers, rebloggedByUsers]) => { + commit('addFavs', { id, favoritedByUsers, currentUser: rootState.users.currentUser }) + commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser }) + }) + }, + fetchFavs ({ rootState, commit }, id) { + rootState.api.backendInteractor.fetchFavoritedByUsers(id) + .then(favoritedByUsers => commit('addFavs', { id, favoritedByUsers, currentUser: rootState.users.currentUser })) + }, + fetchRepeats ({ rootState, commit }, id) { + rootState.api.backendInteractor.fetchRebloggedByUsers(id) + .then(rebloggedByUsers => commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser })) } }, mutations