reports visibility setting + actual filtering for desktop notifs
This commit is contained in:
parent
d178a56924
commit
072a06fc89
@ -114,6 +114,21 @@
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4> {{ $t('settings.notification_visibility_follow_requests') }}</h4>
|
||||
<ul class="setting-list">
|
||||
<li>
|
||||
<BooleanSetting path="notificationVisibility.follow_request">
|
||||
{{ $t('settings.notification_visibility_in_column') }}
|
||||
</BooleanSetting>
|
||||
</li>
|
||||
<li>
|
||||
<BooleanSetting path="notificationNative.follow_request" >
|
||||
{{ $t('settings.notification_visibility_native_notifications') }}
|
||||
</BooleanSetting>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4> {{ $t('settings.notification_visibility_moves') }}</h4>
|
||||
<ul class="setting-list">
|
||||
|
@ -564,6 +564,7 @@
|
||||
"notification_visibility_in_column": "Show in notifications column/drawer",
|
||||
"notification_visibility_native_notifications": "Show a native notification",
|
||||
"notification_visibility_follows": "Follows",
|
||||
"notification_visibility_follow_requests": "Follow requests",
|
||||
"notification_visibility_likes": "Favorites",
|
||||
"notification_visibility_mentions": "Mentions",
|
||||
"notification_visibility_repeats": "Repeats",
|
||||
|
@ -91,6 +91,7 @@ export const prepareNotificationObject = (notification, i18n) => {
|
||||
|
||||
const notifObj = {
|
||||
tag: notification.id,
|
||||
type: notification.type,
|
||||
badge: cachedBadgeUrl
|
||||
}
|
||||
const status = notification.status
|
||||
|
51
src/sw.js
51
src/sw.js
@ -15,7 +15,8 @@ const i18n = createI18n({
|
||||
|
||||
const state = {
|
||||
lastFocused: null,
|
||||
notificationIds: new Set()
|
||||
notificationIds: new Set(),
|
||||
allowedNotificationTypes: null
|
||||
}
|
||||
|
||||
function getWindowClients () {
|
||||
@ -23,15 +24,43 @@ function getWindowClients () {
|
||||
.then((clientList) => clientList.filter(({ type }) => type === 'window'))
|
||||
}
|
||||
|
||||
const setLocale = async () => {
|
||||
const state = await localForage.getItem('vuex-lz')
|
||||
const locale = state.config.interfaceLanguage || 'en'
|
||||
const setSettings = async () => {
|
||||
const vuexState = await localForage.getItem('vuex-lz')
|
||||
const locale = vuexState.config.interfaceLanguage || 'en'
|
||||
i18n.locale = locale
|
||||
const notificationsNativeArray = Object.entries(vuexState.config.notificationNative)
|
||||
|
||||
state.allowedNotificationTypes = new Set(
|
||||
notificationsNativeArray
|
||||
.filter(([k, v]) => v)
|
||||
.map(([k]) => {
|
||||
switch (k) {
|
||||
case 'mentions':
|
||||
return 'mention'
|
||||
case 'likes':
|
||||
return 'like'
|
||||
case 'repeats':
|
||||
return 'repeat'
|
||||
case 'emojiReactions':
|
||||
return 'pleroma:emoji_reaction'
|
||||
case 'reports':
|
||||
return 'pleroma:report'
|
||||
case 'followRequest':
|
||||
return 'follow_request'
|
||||
case 'follows':
|
||||
return 'follow'
|
||||
case 'polls':
|
||||
return 'poll'
|
||||
default:
|
||||
return k
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const showPushNotification = async (event) => {
|
||||
const activeClients = await getWindowClients()
|
||||
await setLocale()
|
||||
await setSettings()
|
||||
// Only show push notifications if all tabs/windows are closed
|
||||
if (activeClients.length === 0) {
|
||||
const data = event.data.json()
|
||||
@ -43,27 +72,31 @@ const showPushNotification = async (event) => {
|
||||
|
||||
const res = prepareNotificationObject(parsedNotification, i18n)
|
||||
|
||||
self.registration.showNotification(res.title, res)
|
||||
if (state.allowedNotificationTypes.has(parsedNotification.type)) {
|
||||
self.registration.showNotification(res.title, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.addEventListener('push', async (event) => {
|
||||
console.log(event)
|
||||
if (event.data) {
|
||||
event.waitUntil(showPushNotification(event))
|
||||
}
|
||||
})
|
||||
|
||||
self.addEventListener('message', async (event) => {
|
||||
await setSettings()
|
||||
const { type, content } = event.data
|
||||
|
||||
if (type === 'desktopNotification') {
|
||||
const { title, ...rest } = content
|
||||
const { tag } = rest
|
||||
const { tag, type } = rest
|
||||
if (state.notificationIds.has(tag)) return
|
||||
state.notificationIds.add(tag)
|
||||
setTimeout(() => state.notificationIds.delete(tag), 10000)
|
||||
self.registration.showNotification(title, rest)
|
||||
if (state.allowedNotificationTypes.has(type)) {
|
||||
self.registration.showNotification(title, rest)
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'desktopNotificationClose') {
|
||||
|
Loading…
Reference in New Issue
Block a user