From ea27483f2728b5c2f1dd57228b8bf1ab9ae223ff Mon Sep 17 00:00:00 2001 From: jasper Date: Wed, 3 Apr 2019 09:04:46 -0700 Subject: [PATCH] Fix notification bugs --- src/components/notifications/notifications.js | 7 --- src/modules/statuses.js | 43 +++++++++++-------- src/modules/users.js | 6 ++- .../backend_interactor_service.js | 2 + 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index d3db4b29..d9ce7604 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -10,13 +10,6 @@ const Notifications = { props: [ 'noHeading' ], - created () { - const store = this.$store - const credentials = store.state.users.currentUser.credentials - - const fetcherId = notificationsFetcher.startFetching({ store, credentials }) - this.$store.commit('setNotificationFetcher', { fetcherId }) - }, data () { return { bottomedOut: false diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 8e0203e3..660d5c26 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -20,20 +20,22 @@ const emptyTl = (userId = 0) => ({ flushMarker: 0 }) +const emptyNotifications = () => ({ + desktopNotificationSilence: true, + maxId: 0, + minId: Number.POSITIVE_INFINITY, + data: [], + idStore: {}, + loading: false, + error: false, + fetcherId: null +}) + export const defaultState = () => ({ allStatuses: [], allStatusesObject: {}, maxId: 0, - notifications: { - desktopNotificationSilence: true, - maxId: 0, - minId: Number.POSITIVE_INFINITY, - data: [], - idStore: {}, - loading: false, - error: false, - fetcherId: null - }, + notifications: emptyNotifications(), favorites: new Set(), error: false, timelines: { @@ -340,9 +342,9 @@ export const mutations = { oldTimeline.visibleStatusesObject = {} each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) }, - setNotificationFetcher (state, { fetcherId }) { - state.notifications.fetcherId = fetcherId - }, + // setNotificationFetcher (state, { fetcherId }) { + // state.notifications.fetcherId = fetcherId + // }, resetStatuses (state) { const emptyState = defaultState() Object.entries(emptyState).forEach(([key, value]) => { @@ -352,6 +354,9 @@ export const mutations = { clearTimeline (state, { timeline }) { state.timelines[timeline] = emptyTl(state.timelines[timeline].userId) }, + clearNotifications (state) { + state.notifications = emptyNotifications() + }, setFavorited (state, { status, value }) { const newStatus = state.allStatusesObject[status.id] newStatus.favorited = value @@ -428,12 +433,12 @@ const statuses = { setNotificationsSilence ({ rootState, commit }, { value }) { commit('setNotificationsSilence', { value }) }, - stopFetchingNotifications ({ rootState, commit }) { - if (rootState.statuses.notifications.fetcherId) { - window.clearInterval(rootState.statuses.notifications.fetcherId) - } - commit('setNotificationFetcher', { fetcherId: null }) - }, + // stopFetchingNotifications ({ rootState, commit }) { + // if (rootState.statuses.notifications.fetcherId) { + // window.clearInterval(rootState.statuses.notifications.fetcherId) + // } + // commit('setNotificationFetcher', { fetcherId: null }) + // }, deleteStatus ({ rootState, commit }, status) { commit('setDeleted', { status }) apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials }) diff --git a/src/modules/users.js b/src/modules/users.js index 1a507d31..3cfae1fc 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -331,7 +331,8 @@ const users = { store.commit('setToken', false) store.dispatch('stopFetching', 'friends') store.commit('setBackendInteractor', backendInteractorService()) - store.dispatch('stopFetchingNotifications') + store.dispatch('stopFetching', 'notifications') + store.commit('clearNotifications') store.commit('resetStatuses') }, loginUser (store, accessToken) { @@ -365,6 +366,9 @@ const users = { // Start getting fresh posts. store.dispatch('startFetching', { timeline: 'friends' }) + // Start fetching notifications + store.dispatch('startFetching', { timeline: 'notifications' }) + // Get user mutes store.dispatch('fetchMutes') diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 71e78d2f..f28686f8 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -1,5 +1,6 @@ import apiService from '../api/api.service.js' import timelineFetcherService from '../timeline_fetcher/timeline_fetcher.service.js' +import notificationsFetcher from '../notifications_fetcher/notifications_fetcher.service.js' const backendInteractorService = (credentials) => { const fetchStatus = ({id}) => { @@ -59,6 +60,7 @@ const backendInteractorService = (credentials) => { } const startFetching = ({timeline, store, userId = false, tag}) => { + if (timeline === 'notifications') { return notificationsFetcher.startFetching({store, credentials}) } return timelineFetcherService.startFetching({timeline, store, credentials, userId, tag}) }