handle desktop notifications clicks
This commit is contained in:
parent
6ed2cb8f43
commit
a17defc5ab
@ -345,7 +345,7 @@ const afterStoreSetup = async ({ store, i18n }) => {
|
|||||||
store.dispatch('setLayoutHeight', windowHeight())
|
store.dispatch('setLayoutHeight', windowHeight())
|
||||||
|
|
||||||
FaviconService.initFaviconService()
|
FaviconService.initFaviconService()
|
||||||
initServiceWorker()
|
initServiceWorker(store)
|
||||||
|
|
||||||
window.addEventListener('focus', () => updateFocus())
|
window.addEventListener('focus', () => updateFocus())
|
||||||
|
|
||||||
|
@ -159,14 +159,16 @@ const Notifications = {
|
|||||||
updateScrollPosition () {
|
updateScrollPosition () {
|
||||||
this.showScrollTop = this.$refs.root.offsetTop < this.scrollerRef.scrollTop
|
this.showScrollTop = this.$refs.root.offsetTop < this.scrollerRef.scrollTop
|
||||||
},
|
},
|
||||||
|
/* "Interacted" really refers to "actionable" notifications that require user input,
|
||||||
|
* everything else (likes/repeats/reacts) cannot be acted and therefore we just clear
|
||||||
|
* the "seen" status upon any clicks on them
|
||||||
|
*/
|
||||||
notificationClicked (notification) {
|
notificationClicked (notification) {
|
||||||
// const { type, id, seen } = notification
|
const { id } = notification
|
||||||
|
this.$store.dispatch('notificationClicked', { id })
|
||||||
},
|
},
|
||||||
notificationInteracted (notification) {
|
notificationInteracted (notification) {
|
||||||
const { id, seen } = notification
|
const { id } = notification
|
||||||
if (!seen) this.markOneAsSeen(id)
|
|
||||||
},
|
|
||||||
markOneAsSeen (id) {
|
|
||||||
this.$store.dispatch('markSingleNotificationAsSeen', { id })
|
this.$store.dispatch('markSingleNotificationAsSeen', { id })
|
||||||
},
|
},
|
||||||
markAsSeen () {
|
markAsSeen () {
|
||||||
|
@ -113,6 +113,21 @@ export const notifications = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
notificationClicked ({ state, commit }, id) {
|
||||||
|
const notification = state.idStore[id]
|
||||||
|
const { type, seen } = notification
|
||||||
|
|
||||||
|
if (!seen) {
|
||||||
|
switch (type) {
|
||||||
|
case 'mention':
|
||||||
|
case 'pleroma:report':
|
||||||
|
case 'follow_request':
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
commit('markSingleNotificationAsSeen', { id })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
setNotificationsLoading ({ rootState, commit }, { value }) {
|
setNotificationsLoading ({ rootState, commit }, { value }) {
|
||||||
commit('setNotificationsLoading', { value })
|
commit('setNotificationsLoading', { value })
|
||||||
},
|
},
|
||||||
|
@ -82,12 +82,18 @@ function sendSubscriptionToBackEnd (subscription, token, notificationVisibility)
|
|||||||
return responseData
|
return responseData
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
export async function initServiceWorker () {
|
export async function initServiceWorker (store) {
|
||||||
if (!isSWSupported()) return
|
if (!isSWSupported()) return
|
||||||
await getOrCreateServiceWorker()
|
await getOrCreateServiceWorker()
|
||||||
navigator.serviceWorker.addEventListener('message', (event) => {
|
navigator.serviceWorker.addEventListener('message', (event) => {
|
||||||
|
const { dispatch } = store
|
||||||
console.log('SW MESSAGE', event)
|
console.log('SW MESSAGE', event)
|
||||||
// TODO actually act upon click (open drawer on mobile, open chat/thread etc)
|
const { type, ...rest } = event
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'notificationClicked':
|
||||||
|
dispatch('notificationClicked', { id: rest.id })
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user