implement new muting
This commit is contained in:
parent
57aa8818a9
commit
8d640d0b79
5 changed files with 48 additions and 27 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { muteWordHits } from '../status_parser/status_parser.js'
|
||||
import { muteFilterHits } from '../status_parser/status_parser.js'
|
||||
import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
|
||||
import { useI18nStore } from 'src/stores/i18n.js'
|
||||
import { useAnnouncementsStore } from 'src/stores/announcements'
|
||||
|
|
@ -58,10 +58,10 @@ const sortById = (a, b) => {
|
|||
}
|
||||
}
|
||||
|
||||
const isMutedNotification = (store, notification) => {
|
||||
if (!notification.status) return
|
||||
const rootGetters = store.rootGetters || store.getters
|
||||
return notification.status.muted || muteWordHits(notification.status, rootGetters.mergedConfig.muteWords).length > 0
|
||||
const isMutedNotification = (notification) => {
|
||||
if (!notification.status) return false
|
||||
if (notification.status.muted) return true
|
||||
return muteFilterHits(notification.status).length > 0
|
||||
}
|
||||
|
||||
export const maybeShowNotification = (store, notification) => {
|
||||
|
|
@ -69,7 +69,7 @@ export const maybeShowNotification = (store, notification) => {
|
|||
|
||||
if (notification.seen) return
|
||||
if (!visibleTypes(store).includes(notification.type)) return
|
||||
if (notification.type === 'mention' && isMutedNotification(store, notification)) return
|
||||
if (notification.type === 'mention' && isMutedNotification(notification)) return
|
||||
|
||||
const notificationObject = prepareNotificationObject(notification, useI18nStore().i18n)
|
||||
showDesktopNotification(rootState, notificationObject)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,30 @@
|
|||
import { filter } from 'lodash'
|
||||
import { useServerSideStorageStore } from 'src/stores/serverSideStorage'
|
||||
|
||||
export const muteWordHits = (status, muteWords) => {
|
||||
export const muteFilterHits = (status) => {
|
||||
const statusText = status.text.toLowerCase()
|
||||
const statusSummary = status.summary.toLowerCase()
|
||||
const hits = filter(muteWords, (muteWord) => {
|
||||
return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase())
|
||||
})
|
||||
|
||||
return hits
|
||||
const muteFilters = Object.values(useServerSideStorageStore().prefsStorage.simple.muteFilters)
|
||||
|
||||
return muteFilters.toSorted((a,b) => b.order - a.order).map(filter => {
|
||||
const { hide, expires, name, value, type} = filter
|
||||
if (expires !== null && expires < Date.now()) return false
|
||||
switch (type) {
|
||||
case 'word': {
|
||||
if (statusText.includes(value) || statusSummary.includes(value)) {
|
||||
return { hide, name }
|
||||
}
|
||||
}
|
||||
case 'regexp': {
|
||||
try {
|
||||
const re = new RegExp(value, 'i')
|
||||
if (re.test(statusText) || re.test(statusSummary)) {
|
||||
return { hide, name }
|
||||
}
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}).filter(_ => _)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue