logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe
commit: 53e104dc32080965a5a28ec37975b0c229a7d083
parent: bbe4f3e3af54bfcb6f53bc57f66f790f4163bfb0
Author: Shpuld Shpludson <shp@cock.li>
Date:   Fri,  1 Mar 2019 18:03:30 +0000

Merge branch 'issue-388-request-count-broken' into 'develop'

#388: get follow request on a real-time basis

Closes #388

See merge request pleroma/pleroma-fe!619

Diffstat:

Msrc/components/follow_requests/follow_requests.js9---------
Msrc/components/nav_panel/nav_panel.js13+++++++++++++
Msrc/components/nav_panel/nav_panel.vue4++--
Msrc/components/side_drawer/side_drawer.js3+++
Msrc/components/side_drawer/side_drawer.vue4++--
Asrc/services/follow_request_fetcher/follow_request_fetcher.service.js21+++++++++++++++++++++
6 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/src/components/follow_requests/follow_requests.js b/src/components/follow_requests/follow_requests.js @@ -4,19 +4,10 @@ const FollowRequests = { components: { FollowRequestCard }, - 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 @@ -1,10 +1,23 @@ +import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service' + const NavPanel = { + created () { + if (this.currentUser && this.currentUser.locked) { + const store = this.$store + const credentials = store.state.users.currentUser.credentials + + followRequestFetcher.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 @@ -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/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 @@ -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/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_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 followRequestFetcher = { + startFetching +} + +export default followRequestFetcher