Fix notification bugs

This commit is contained in:
jasper 2019-04-03 09:04:46 -07:00
parent ac28e8c2f9
commit ea27483f27
4 changed files with 31 additions and 27 deletions

View file

@ -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

View file

@ -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 })

View file

@ -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')

View file

@ -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})
}