From f74a6b4b5777211dcda979b0e390305f46efdd95 Mon Sep 17 00:00:00 2001
From: Brenden Bice <brenden.next@gmail.com>
Date: Tue, 9 Apr 2019 04:00:09 -0400
Subject: display favs & reblogged users on expanded post in timeline view

---
 src/components/timeline/timeline.vue | 1 +
 1 file changed, 1 insertion(+)

(limited to 'src/components/timeline/timeline.vue')

diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue
index e0a34bd1..147e8a1d 100644
--- a/src/components/timeline/timeline.vue
+++ b/src/components/timeline/timeline.vue
@@ -22,6 +22,7 @@
           :key="status.id"
           :statusoid="status"
           :collapsable="true"
+          :timelineName="timelineName"
         />
       </div>
     </div>
-- 
cgit v1.2.3-70-g09d2


From 8ed4eb8a7ffe0e370cfc06017d2bce34b2c9d987 Mon Sep 17 00:00:00 2001
From: Brenden Bice <brenden.next@gmail.com>
Date: Tue, 9 Apr 2019 11:45:33 -0400
Subject: refactor showing favs and repeats logic

---
 src/components/conversation/conversation.js        |  6 ++--
 src/components/status/status.js                    |  7 +++-
 src/components/status/status.vue                   |  8 ++---
 src/components/timeline/timeline.vue               |  3 +-
 src/modules/statuses.js                            | 39 +++++-----------------
 .../backend_interactor_service.js                  |  4 +--
 6 files changed, 23 insertions(+), 44 deletions(-)

(limited to 'src/components/timeline/timeline.vue')

diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js
index 5cc7f4ee..ffeb7244 100644
--- a/src/components/conversation/conversation.js
+++ b/src/components/conversation/conversation.js
@@ -41,8 +41,7 @@ const conversation = {
   props: [
     'statusoid',
     'collapsable',
-    'isPage',
-    'timelineName'
+    'isPage'
   ],
   created () {
     if (this.isPage) {
@@ -121,8 +120,6 @@ const conversation = {
       if (this.status) {
         this.$store.state.api.backendInteractor.fetchConversation({id: this.status.id})
           .then(({ancestors, descendants}) => {
-            this.$store.dispatch('fetchFavoritedByUsers', { id: this.statusId, retweetedStatusId: this.status.id, timelineName: this.timelineName })
-            this.$store.dispatch('fetchRebloggedByUsers', { id: this.statusId, retweetedStatusId: this.status.id, timelineName: this.timelineName })
             this.$store.dispatch('addNewStatuses', { statuses: ancestors })
             this.$store.dispatch('addNewStatuses', { statuses: descendants })
           })
@@ -142,6 +139,7 @@ const conversation = {
     },
     setHighlight (id) {
       this.highlight = id
+      this.$store.dispatch('fetchFavsAndRepeats', id)
     },
     getHighlight () {
       return this.isExpanded ? this.highlight : null
diff --git a/src/components/status/status.js b/src/components/status/status.js
index 44caf3af..db234ec1 100644
--- a/src/components/status/status.js
+++ b/src/components/status/status.js
@@ -98,6 +98,10 @@ const Status = {
         return this.statusoid
       }
     },
+    statusFromGlobalRepository () {
+      // NOTE: Consider to replace status with statusFromGlobalRepository
+      return this.$store.state.statuses.allStatusesObject[this.status.id]
+    },
     loggedIn () {
       return !!this.$store.state.users.currentUser
     },
@@ -260,7 +264,8 @@ const Status = {
       return this.status.summary_html + '<br />' + this.status.statusnet_html
     },
     combinedFavsAndRepeatsAvatars () {
-      const combinedAvatars = [].concat(this.statusoid.favoritedBy, this.statusoid.rebloggedBy).filter(_ => _)
+      // Use the status from the global status repository since favs and repeats are saved in it
+      const combinedAvatars = [].concat(this.statusFromGlobalRepository.favoritedBy, this.statusFromGlobalRepository.rebloggedBy).filter(_ => _)
       return uniqBy(combinedAvatars, 'id')
     }
   },
diff --git a/src/components/status/status.vue b/src/components/status/status.vue
index 34bb64d0..b0882964 100644
--- a/src/components/status/status.vue
+++ b/src/components/status/status.vue
@@ -136,13 +136,13 @@
           <transition name="fade">
             <div class="favs-repeated-users" v-if="combinedFavsAndRepeatsAvatars.length > 0 && isFocused">
               <ul class="stats">
-                <li class="stat-count" v-if="statusoid.rebloggedBy && statusoid.rebloggedBy.length > 0">
+                <li class="stat-count" v-if="statusFromGlobalRepository.rebloggedBy && statusFromGlobalRepository.rebloggedBy.length > 0">
                   <a class="stat-title">{{ $t('settings.notification_visibility_repeats') }}</a>
-                  <div class="stat-number">{{ statusoid.rebloggedBy.length }}</div>
+                  <div class="stat-number">{{ statusFromGlobalRepository.rebloggedBy.length }}</div>
                 </li>
-                <li class="stat-count" v-if="statusoid.favoritedBy && statusoid.favoritedBy.length > 0">
+                <li class="stat-count" v-if="statusFromGlobalRepository.favoritedBy && statusFromGlobalRepository.favoritedBy.length > 0">
                   <a class="stat-title">{{ $t('user_card.favorites') }}</a>
-                  <div class="stat-number">{{ statusoid.favoritedBy.length }}</div>
+                  <div class="stat-number">{{ statusFromGlobalRepository.favoritedBy.length }}</div>
                 </li>
                 <li class="avatar-row">
                   <AvatarList :avatars='combinedFavsAndRepeatsAvatars'></AvatarList>
diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue
index 147e8a1d..e6a8d458 100644
--- a/src/components/timeline/timeline.vue
+++ b/src/components/timeline/timeline.vue
@@ -16,13 +16,12 @@
     </div>
     <div :class="classes.body">
       <div class="timeline">
-        <conversation 
+        <conversation
           v-for="status in timeline.visibleStatuses"
           class="status-fadein"
           :key="status.id"
           :statusoid="status"
           :collapsable="true"
-          :timelineName="timelineName"
         />
       </div>
     </div>
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 023f132e..527cafc2 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -460,32 +460,11 @@ export const mutations = {
   queueFlush (state, { timeline, id }) {
     state.timelines[timeline].flushMarker = id
   },
-  addFavoritedByUsers (state, { favoritedByUsers, id, timelineName }) {
-    if (timelineName) {
-      state.timelines[timelineName].visibleStatusesObject[id] = {
-        ...state.timelines[timelineName].visibleStatusesObject[id],
-        favoritedBy: favoritedByUsers
-      }
-      state.timelines[timelineName].visibleStatuses = state.timelines[timelineName].visibleStatuses.map(visibleStatus => visibleStatus.id === id ? { ...visibleStatus, favoritedBy: favoritedByUsers } : visibleStatus)
-    } else {
-      state.allStatusesObject[id] = {
-        ...state.allStatusesObject[id],
-        favoritedBy: favoritedByUsers
-      }
-    }
-  },
-  addRebloggedByUsers (state, { rebloggedByUsers, id, timelineName }) {
-    if (timelineName) {
-      state.timelines[timelineName].visibleStatusesObject[id] = {
-        ...state.timelines[timelineName].visibleStatusesObject[id],
-        rebloggedBy: rebloggedByUsers
-      }
-      state.timelines[timelineName].visibleStatuses = state.timelines[timelineName].visibleStatuses.map(visibleStatus => visibleStatus.id === id ? { ...visibleStatus, rebloggedBy: rebloggedByUsers } : visibleStatus)
-    } else {
-      state.allStatusesObject[id] = {
-        ...state.allStatusesObject[id],
-        rebloggedBy: rebloggedByUsers
-      }
+  addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers }) {
+    state.allStatusesObject[id] = {
+      ...state.allStatusesObject[id],
+      favoritedBy: favoritedByUsers,
+      rebloggedBy: rebloggedByUsers
     }
   }
 }
@@ -553,11 +532,9 @@ const statuses = {
         credentials: rootState.users.currentUser.credentials
       })
     },
-    fetchFavoritedByUsers ({ rootState, commit }, { id, retweetedStatusId, timelineName }) {
-      rootState.api.backendInteractor.fetchFavoritedByUsers({id}).then((favoritedByUsers) => commit('addFavoritedByUsers', { favoritedByUsers, id: retweetedStatusId, timelineName }))
-    },
-    fetchRebloggedByUsers ({ rootState, commit }, { id, retweetedStatusId, timelineName }) {
-      rootState.api.backendInteractor.fetchRebloggedByUsers({id}).then((rebloggedByUsers) => commit('addRebloggedByUsers', { rebloggedByUsers, id: retweetedStatusId, timelineName }))
+    fetchFavsAndRepeats ({ rootState, commit }, id) {
+      Promise.all([rootState.api.backendInteractor.fetchFavoritedByUsers(id), rootState.api.backendInteractor.fetchRebloggedByUsers(id)])
+        .then(([favoritedByUsers, rebloggedByUsers]) => commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers }))
     }
   },
   mutations
diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js
index 0768c806..c6742d26 100644
--- a/src/services/backend_interactor_service/backend_interactor_service.js
+++ b/src/services/backend_interactor_service/backend_interactor_service.js
@@ -112,8 +112,8 @@ const backendInteractorService = (credentials) => {
   const deleteAccount = ({password}) => apiService.deleteAccount({credentials, password})
   const changePassword = ({password, newPassword, newPasswordConfirmation}) => apiService.changePassword({credentials, password, newPassword, newPasswordConfirmation})
 
-  const fetchFavoritedByUsers = ({id}) => apiService.fetchFavoritedByUsers({id})
-  const fetchRebloggedByUsers = ({id}) => apiService.fetchRebloggedByUsers({id})
+  const fetchFavoritedByUsers = (id) => apiService.fetchFavoritedByUsers({id})
+  const fetchRebloggedByUsers = (id) => apiService.fetchRebloggedByUsers({id})
 
   const backendInteractorServiceInstance = {
     fetchStatus,
-- 
cgit v1.2.3-70-g09d2

