Hide initial desktop notifications spam when FE is opened and there's a lot of

unseen notifications.
This commit is contained in:
Henry Jameson 2018-08-20 19:58:49 +03:00
parent fa66385c5b
commit 9e78c64d5e
2 changed files with 12 additions and 1 deletions

View file

@ -24,6 +24,7 @@ export const defaultState = {
allStatusesObject: {}, allStatusesObject: {},
maxId: 0, maxId: 0,
notifications: { notifications: {
desktopNotificationSilence: true,
maxId: 0, maxId: 0,
maxSavedId: 0, maxSavedId: 0,
minId: Number.POSITIVE_INFINITY, minId: Number.POSITIVE_INFINITY,
@ -314,7 +315,7 @@ const addNewNotifications = (state, { dispatch, notifications, older }) => {
result.image = action.attachments[0].url result.image = action.attachments[0].url
} }
if (fresh) { if (fresh && !state.notifications.desktopNotificationSilence) {
let notification = new window.Notification(title, result) let notification = new window.Notification(title, result)
// Chrome is known for not closing notifications automatically // Chrome is known for not closing notifications automatically
// according to MDN, anyway. // according to MDN, anyway.
@ -365,6 +366,9 @@ export const mutations = {
setNotificationsError (state, { value }) { setNotificationsError (state, { value }) {
state.notificationsError = value state.notificationsError = value
}, },
setNotificationsSilence (state, { value }) {
state.notifications.desktopNotificationSilence = value
},
setProfileView (state, { v }) { setProfileView (state, { v }) {
// load followers / friends only when needed // load followers / friends only when needed
state.timelines['user'].viewing = v state.timelines['user'].viewing = v
@ -401,6 +405,9 @@ const statuses = {
setNotificationsError ({ rootState, commit }, { value }) { setNotificationsError ({ rootState, commit }, { value }) {
commit('setNotificationsError', { value }) commit('setNotificationsError', { value })
}, },
setNotificationsSilence ({ rootState, commit }, { value }) {
commit('setNotificationsSilence', { value })
},
addFriends ({ rootState, commit }, { friends }) { addFriends ({ rootState, commit }, { friends }) {
commit('addFriends', { friends }) commit('addFriends', { friends })
}, },

View file

@ -30,6 +30,10 @@ const fetchAndUpdate = ({store, credentials, older = false}) => {
const startFetching = ({credentials, store}) => { const startFetching = ({credentials, store}) => {
fetchAndUpdate({ credentials, store }) fetchAndUpdate({ credentials, store })
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
// Initially there's set flag to silence all desktop notifications so
// that there won't spam of them when user just opened up the FE we
// reset that flag after a while to show new notifications once again.
setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
return setInterval(boundFetchAndUpdate, 10000) return setInterval(boundFetchAndUpdate, 10000)
} }