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: [ props: [
'noHeading' '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 () { data () {
return { return {
bottomedOut: false bottomedOut: false

View file

@ -20,20 +20,22 @@ const emptyTl = (userId = 0) => ({
flushMarker: 0 flushMarker: 0
}) })
const emptyNotifications = () => ({
desktopNotificationSilence: true,
maxId: 0,
minId: Number.POSITIVE_INFINITY,
data: [],
idStore: {},
loading: false,
error: false,
fetcherId: null
})
export const defaultState = () => ({ export const defaultState = () => ({
allStatuses: [], allStatuses: [],
allStatusesObject: {}, allStatusesObject: {},
maxId: 0, maxId: 0,
notifications: { notifications: emptyNotifications(),
desktopNotificationSilence: true,
maxId: 0,
minId: Number.POSITIVE_INFINITY,
data: [],
idStore: {},
loading: false,
error: false,
fetcherId: null
},
favorites: new Set(), favorites: new Set(),
error: false, error: false,
timelines: { timelines: {
@ -340,9 +342,9 @@ export const mutations = {
oldTimeline.visibleStatusesObject = {} oldTimeline.visibleStatusesObject = {}
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
}, },
setNotificationFetcher (state, { fetcherId }) { // setNotificationFetcher (state, { fetcherId }) {
state.notifications.fetcherId = fetcherId // state.notifications.fetcherId = fetcherId
}, // },
resetStatuses (state) { resetStatuses (state) {
const emptyState = defaultState() const emptyState = defaultState()
Object.entries(emptyState).forEach(([key, value]) => { Object.entries(emptyState).forEach(([key, value]) => {
@ -352,6 +354,9 @@ export const mutations = {
clearTimeline (state, { timeline }) { clearTimeline (state, { timeline }) {
state.timelines[timeline] = emptyTl(state.timelines[timeline].userId) state.timelines[timeline] = emptyTl(state.timelines[timeline].userId)
}, },
clearNotifications (state) {
state.notifications = emptyNotifications()
},
setFavorited (state, { status, value }) { setFavorited (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
newStatus.favorited = value newStatus.favorited = value
@ -428,12 +433,12 @@ const statuses = {
setNotificationsSilence ({ rootState, commit }, { value }) { setNotificationsSilence ({ rootState, commit }, { value }) {
commit('setNotificationsSilence', { value }) commit('setNotificationsSilence', { value })
}, },
stopFetchingNotifications ({ rootState, commit }) { // stopFetchingNotifications ({ rootState, commit }) {
if (rootState.statuses.notifications.fetcherId) { // if (rootState.statuses.notifications.fetcherId) {
window.clearInterval(rootState.statuses.notifications.fetcherId) // window.clearInterval(rootState.statuses.notifications.fetcherId)
} // }
commit('setNotificationFetcher', { fetcherId: null }) // commit('setNotificationFetcher', { fetcherId: null })
}, // },
deleteStatus ({ rootState, commit }, status) { deleteStatus ({ rootState, commit }, status) {
commit('setDeleted', { status }) commit('setDeleted', { status })
apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials }) apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials })

View file

@ -331,7 +331,8 @@ const users = {
store.commit('setToken', false) store.commit('setToken', false)
store.dispatch('stopFetching', 'friends') store.dispatch('stopFetching', 'friends')
store.commit('setBackendInteractor', backendInteractorService()) store.commit('setBackendInteractor', backendInteractorService())
store.dispatch('stopFetchingNotifications') store.dispatch('stopFetching', 'notifications')
store.commit('clearNotifications')
store.commit('resetStatuses') store.commit('resetStatuses')
}, },
loginUser (store, accessToken) { loginUser (store, accessToken) {
@ -365,6 +366,9 @@ const users = {
// Start getting fresh posts. // Start getting fresh posts.
store.dispatch('startFetching', { timeline: 'friends' }) store.dispatch('startFetching', { timeline: 'friends' })
// Start fetching notifications
store.dispatch('startFetching', { timeline: 'notifications' })
// Get user mutes // Get user mutes
store.dispatch('fetchMutes') store.dispatch('fetchMutes')

View file

@ -1,5 +1,6 @@
import apiService from '../api/api.service.js' import apiService from '../api/api.service.js'
import timelineFetcherService from '../timeline_fetcher/timeline_fetcher.service.js' import timelineFetcherService from '../timeline_fetcher/timeline_fetcher.service.js'
import notificationsFetcher from '../notifications_fetcher/notifications_fetcher.service.js'
const backendInteractorService = (credentials) => { const backendInteractorService = (credentials) => {
const fetchStatus = ({id}) => { const fetchStatus = ({id}) => {
@ -59,6 +60,7 @@ const backendInteractorService = (credentials) => {
} }
const startFetching = ({timeline, store, userId = false, tag}) => { const startFetching = ({timeline, store, userId = false, tag}) => {
if (timeline === 'notifications') { return notificationsFetcher.startFetching({store, credentials}) }
return timelineFetcherService.startFetching({timeline, store, credentials, userId, tag}) return timelineFetcherService.startFetching({timeline, store, credentials, userId, tag})
} }