From 17498ef906b79dd68276faa2a5624b90f3f0bc2b Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 24 Jun 2019 04:21:09 -0400 Subject: [PATCH 1/4] 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 }) ) } }, From e9b6e0e2b74ac4f9c8558c3329c70eee1c869abc Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 24 Jun 2019 05:19:43 -0400 Subject: [PATCH 2/4] refetch favs and repeats when stats are changed --- src/components/status/status.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/status/status.js b/src/components/status/status.js index 4b3499cd..6f83dbe0 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -402,6 +402,9 @@ 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: { @@ -419,6 +422,16 @@ const Status = { window.scrollBy(0, rect.bottom - window.innerHeight + 50) } } + }, + 'status.repeat_num': function (num) { + if (this.isFocused && this.statusFromGlobalRepository.rebloggedBy && this.statusFromGlobalRepository.rebloggedBy.length !== num) { + this.refetchFavsAndRepeats() + } + }, + 'status.fave_num': function (num) { + if (this.isFocused && this.statusFromGlobalRepository.favoritedBy && this.statusFromGlobalRepository.favoritedBy.length !== num) { + this.refetchFavsAndRepeats() + } } }, filters: { From ab4d7d9616319778b7ed5d79ca1f389c9e439113 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 27 Jun 2019 08:14:54 -0400 Subject: [PATCH 3/4] 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 From 0131effb013025edae843ed7c92ef8fdf43a3623 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 27 Jun 2019 08:19:35 -0400 Subject: [PATCH 4/4] add comments --- src/components/status/status.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/status/status.js b/src/components/status/status.js index 284c657c..7911d40d 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -421,11 +421,13 @@ const Status = { } }, 'status.repeat_num': function (num) { + // refetch repeats when repeat_num is changed in any way if (this.isFocused && this.statusFromGlobalRepository.rebloggedBy && this.statusFromGlobalRepository.rebloggedBy.length !== num) { this.$store.dispatch('fetchRepeats', this.status.id) } }, 'status.fave_num': function (num) { + // refetch favs when fave_num is changed in any way if (this.isFocused && this.statusFromGlobalRepository.favoritedBy && this.statusFromGlobalRepository.favoritedBy.length !== num) { this.$store.dispatch('fetchFavs', this.status.id) }