From ef515056b5cee27c2b62f3287349c58b67c286e4 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 13 Aug 2018 13:17:10 +0300 Subject: [PATCH] missing files and a plug for bad favs --- src/components/notification/notification.vue | 7 +++- .../notifications_fetcher.service.js | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/services/notifications_fetcher/notifications_fetcher.service.js diff --git a/src/components/notification/notification.vue b/src/components/notification/notification.vue index 1c07bae9..5d50e72a 100644 --- a/src/components/notification/notification.vue +++ b/src/components/notification/notification.vue @@ -24,12 +24,15 @@ {{$t('notifications.followed_you')}} - +
@{{notification.action.user.screen_name}}
- + +
+ Favorite for missing post +
diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js new file mode 100644 index 00000000..5aedc4fb --- /dev/null +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -0,0 +1,41 @@ +import apiService from '../api/api.service.js' + +const update = ({store, notifications, older}) => { + store.dispatch('setNotificationsError', { value: false }) + + store.dispatch('addNewNotifications', { notifications, older }) +} + +const fetchAndUpdate = ({store, credentials, older = false}) => { + const args = { credentials } + const rootState = store.rootState || store.state + const timelineData = rootState.statuses.notifications + + if (older) { + if (timelineData.minId !== Number.POSITIVE_INFINITY) { + args['until'] = timelineData.minId + } + } else { + args['since'] = timelineData.maxId + } + + args['timeline'] = 'notifications' + + return apiService.fetchTimeline(args) + .then((notifications) => { + update({store, notifications, older}) + }, () => store.dispatch('setNotificationsError', { value: true })) +} + +const startFetching = ({credentials, store}) => { + fetchAndUpdate({ credentials, store }) + const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) + return setInterval(boundFetchAndUpdate, 10000) +} + +const notificationsFetcher = { + fetchAndUpdate, + startFetching +} + +export default notificationsFetcher