add options for marking single notification as read
This commit is contained in:
parent
c059f4a7ee
commit
ec2937ec1f
11 changed files with 85 additions and 4 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import { showDesktopNotification as swDesktopNotification, isSWSupported } from '../sw/sw.js'
|
||||
import {
|
||||
showDesktopNotification as swDesktopNotification,
|
||||
closeDesktopNotification as swCloseDesktopNotification,
|
||||
isSWSupported
|
||||
} from '../sw/sw.js'
|
||||
const state = { failCreateNotif: false }
|
||||
|
||||
export const showDesktopNotification = (rootState, desktopNotificationOpts) => {
|
||||
|
|
@ -16,3 +20,19 @@ export const showDesktopNotification = (rootState, desktopNotificationOpts) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const closeDesktopNotification = (rootState, id) => {
|
||||
if (!('Notification' in window && window.Notification.permission === 'granted')) return
|
||||
|
||||
if (isSWSupported()) {
|
||||
swCloseDesktopNotification({ id })
|
||||
}
|
||||
}
|
||||
|
||||
export const closeAllDesktopNotifications = (rootState) => {
|
||||
if (!('Notification' in window && window.Notification.permission === 'granted')) return
|
||||
|
||||
if (isSWSupported()) {
|
||||
swCloseDesktopNotification()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { filter, sortBy, includes } from 'lodash'
|
||||
import { muteWordHits } from '../status_parser/status_parser.js'
|
||||
import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
|
||||
|
||||
import FaviconService from 'src/services/favicon_service/favicon_service.js'
|
||||
|
||||
let cachedBadgeUrl = null
|
||||
|
|
@ -68,8 +69,8 @@ export const maybeShowNotification = (store, notification) => {
|
|||
|
||||
export const filteredNotificationsFromStore = (store, types) => {
|
||||
// map is just to clone the array since sort mutates it and it causes some issues
|
||||
let sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById)
|
||||
sortedNotifications = sortBy(sortedNotifications, 'seen')
|
||||
const sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById)
|
||||
// TODO implement sorting elsewhere and make it optional
|
||||
return sortedNotifications.filter(
|
||||
(notification) => (types || visibleTypes(store)).includes(notification.type)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -96,6 +96,15 @@ export async function showDesktopNotification (content) {
|
|||
sw.postMessage({ type: 'desktopNotification', content })
|
||||
}
|
||||
|
||||
export async function closeDesktopNotification ({ id }) {
|
||||
const { active: sw } = await window.navigator.serviceWorker.getRegistration()
|
||||
if (id >= 0) {
|
||||
sw.postMessage({ type: 'desktopNotificationClose', content: { id } })
|
||||
} else {
|
||||
sw.postMessage({ type: 'desktopNotificationClose', content: { all: true } })
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateFocus () {
|
||||
const { active: sw } = await window.navigator.serviceWorker.getRegistration()
|
||||
sw.postMessage({ type: 'updateFocus' })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue