From d831b8191284def1d26fad7811f674a0595cded1 Mon Sep 17 00:00:00 2001
From: eugenijm <eugenijm@protonmail.com>
Date: Mon, 11 Feb 2019 12:41:17 +0300
Subject: Added follow requests counter to nav bar to make it visible
 behorehand

---
 src/components/side_drawer/side_drawer.vue | 4 ++++
 1 file changed, 4 insertions(+)

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

diff --git a/src/components/side_drawer/side_drawer.vue b/src/components/side_drawer/side_drawer.vue
index a6c6f237..8eca7b8c 100644
--- a/src/components/side_drawer/side_drawer.vue
+++ b/src/components/side_drawer/side_drawer.vue
@@ -45,6 +45,10 @@
         <li v-if="currentUser && currentUser.locked" @click="toggleDrawer">
           <router-link to='/friend-requests'>
             {{ $t("nav.friend_requests") }}
+            <span v-if='currentUser.follow_request_count > 0' class="badge follow-request-count">
+              {{currentUser.follow_request_count}}
+            </span>
+
           </router-link>
         </li>
         <li @click="toggleDrawer">
-- 
cgit v1.2.3-70-g09d2


From 7c6446a9dea2a221da643414e87a97d17336215f Mon Sep 17 00:00:00 2001
From: dave <starpumadev@gmail.com>
Date: Wed, 27 Feb 2019 14:38:10 -0500
Subject: #388: get follow request on a real-time basis

---
 src/components/follow_requests/follow_requests.js   |  9 ---------
 src/components/nav_panel/nav_panel.js               | 13 +++++++++++++
 src/components/nav_panel/nav_panel.vue              |  4 ++--
 src/components/notifications/notifications.js       |  1 +
 src/components/side_drawer/side_drawer.js           |  3 +++
 src/components/side_drawer/side_drawer.vue          |  4 ++--
 .../request_fetcher.service.js                      | 21 +++++++++++++++++++++
 7 files changed, 42 insertions(+), 13 deletions(-)
 create mode 100644 src/services/notifications_fetcher/request_fetcher.service.js

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

diff --git a/src/components/follow_requests/follow_requests.js b/src/components/follow_requests/follow_requests.js
index 11a228aa..bf890530 100644
--- a/src/components/follow_requests/follow_requests.js
+++ b/src/components/follow_requests/follow_requests.js
@@ -4,19 +4,10 @@ const FollowRequests = {
   components: {
     UserCard
   },
-  created () {
-    this.updateRequests()
-  },
   computed: {
     requests () {
       return this.$store.state.api.followRequests
     }
-  },
-  methods: {
-    updateRequests () {
-      this.$store.state.api.backendInteractor.fetchFollowRequests()
-        .then((requests) => { this.$store.commit('setFollowRequests', requests) })
-    }
   }
 }
 
diff --git a/src/components/nav_panel/nav_panel.js b/src/components/nav_panel/nav_panel.js
index ea5d7ea4..c4034417 100644
--- a/src/components/nav_panel/nav_panel.js
+++ b/src/components/nav_panel/nav_panel.js
@@ -1,10 +1,23 @@
+import requestFetcher from '../../services/notifications_fetcher/request_fetcher.service.js'
+
 const NavPanel = {
+  created () {
+    if (this.currentUser && this.currentUser.locked) {
+      const store = this.$store
+      const credentials = store.state.users.currentUser.credentials
+
+      requestFetcher.startFetching({ store, credentials })
+    }
+  },
   computed: {
     currentUser () {
       return this.$store.state.users.currentUser
     },
     chat () {
       return this.$store.state.chat.channel
+    },
+    followRequestCount () {
+      return this.$store.state.api.followRequests.length
     }
   }
 }
diff --git a/src/components/nav_panel/nav_panel.vue b/src/components/nav_panel/nav_panel.vue
index 1a269adf..7a7212fb 100644
--- a/src/components/nav_panel/nav_panel.vue
+++ b/src/components/nav_panel/nav_panel.vue
@@ -20,8 +20,8 @@
         <li v-if='currentUser && currentUser.locked'>
           <router-link :to="{ name: 'friend-requests' }">
             {{ $t("nav.friend_requests")}}
-            <span v-if='currentUser.follow_request_count > 0' class="badge follow-request-count">
-              {{currentUser.follow_request_count}}
+            <span v-if='followRequestCount > 0' class="badge follow-request-count">
+              {{followRequestCount}}
             </span>
           </router-link>
         </li>
diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js
index 5e95631a..2c9a84be 100644
--- a/src/components/notifications/notifications.js
+++ b/src/components/notifications/notifications.js
@@ -1,5 +1,6 @@
 import Notification from '../notification/notification.vue'
 import notificationsFetcher from '../../services/notifications_fetcher/notifications_fetcher.service.js'
+
 import {
   notificationsFromStore,
   visibleNotificationsFromStore,
diff --git a/src/components/side_drawer/side_drawer.js b/src/components/side_drawer/side_drawer.js
index 40ffa1dd..b5c49059 100644
--- a/src/components/side_drawer/side_drawer.js
+++ b/src/components/side_drawer/side_drawer.js
@@ -32,6 +32,9 @@ const SideDrawer = {
     },
     sitename () {
       return this.$store.state.instance.name
+    },
+    followRequestCount () {
+      return this.$store.state.api.followRequests.length
     }
   },
   methods: {
diff --git a/src/components/side_drawer/side_drawer.vue b/src/components/side_drawer/side_drawer.vue
index 8eca7b8c..6996380d 100644
--- a/src/components/side_drawer/side_drawer.vue
+++ b/src/components/side_drawer/side_drawer.vue
@@ -45,8 +45,8 @@
         <li v-if="currentUser && currentUser.locked" @click="toggleDrawer">
           <router-link to='/friend-requests'>
             {{ $t("nav.friend_requests") }}
-            <span v-if='currentUser.follow_request_count > 0' class="badge follow-request-count">
-              {{currentUser.follow_request_count}}
+            <span v-if='followRequestCount > 0' class="badge follow-request-count">
+              {{followRequestCount}}
             </span>
 
           </router-link>
diff --git a/src/services/notifications_fetcher/request_fetcher.service.js b/src/services/notifications_fetcher/request_fetcher.service.js
new file mode 100644
index 00000000..beb6c320
--- /dev/null
+++ b/src/services/notifications_fetcher/request_fetcher.service.js
@@ -0,0 +1,21 @@
+import apiService from '../api/api.service.js'
+
+const fetchAndUpdate = ({ store, credentials }) => {
+  return apiService.fetchFollowRequests({ credentials })
+    .then((requests) => {
+      store.commit('setFollowRequests', requests)
+    }, () => {})
+    .catch(() => {})
+}
+
+const startFetching = ({credentials, store}) => {
+  fetchAndUpdate({ credentials, store })
+  const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
+  return setInterval(boundFetchAndUpdate, 10000)
+}
+
+const requestFetcher = {
+  startFetching
+}
+
+export default requestFetcher
-- 
cgit v1.2.3-70-g09d2

