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