Move regex creation to filtering tab logic

This commit is contained in:
Norm 2024-12-18 22:45:05 -05:00
parent 105154a42b
commit ef6f8586c2
4 changed files with 25 additions and 8 deletions

View file

@ -1,14 +1,17 @@
import { filter, trim, debounce } from 'lodash'
import { debounce } from 'lodash'
import BooleanSetting from '../helpers/boolean_setting.vue'
import ChoiceSetting from '../helpers/choice_setting.vue'
import IntegerSetting from '../helpers/integer_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js'
const regexStart = '~r/'
const regexEnd = '/'
const FilteringTab = {
data () {
return {
muteWordsStringLocal: this.$store.getters.mergedConfig.muteWords.join('\n'),
muteWordsStringLocal: this.$store.getters.mergedConfig.muteWords.raw,
replyVisibilityOptions: ['all', 'following', 'self'].map(mode => ({
key: mode,
value: mode,
@ -31,7 +34,19 @@ const FilteringTab = {
this.muteWordsStringLocal = value
this.$store.dispatch('setOption', {
name: 'muteWords',
value: filter(value.split('\n'), (word) => trim(word).length > 0)
value: {
raw: value,
value: value.split('\n')
.filter((word) => word.trim().length > 0)
.map((word) => {
if (!(word.startsWith(regexStart) && word.endsWith(regexEnd))) {
return word
}
const regex = new RegExp(word.slice(regexStart.length, -regexEnd.length), 'i')
return regex
})
}
})
}, 500)
}

View file

@ -170,7 +170,7 @@ const Status = {
computed: {
...controlledOrUncontrolledGetters(['replying', 'quoting', 'mediaPlaying']),
muteWords () {
return this.mergedConfig.muteWords
return this.mergedConfig.muteWords.value
},
showReasonMutedThread () {
return (

View file

@ -48,7 +48,7 @@ const sortById = (a, b) => {
const isMutedNotification = (store, notification) => {
if (!notification.status) return
return notification.status.muted || muteWordHits(notification.status, store.rootGetters.mergedConfig.muteWords).length > 0
return notification.status.muted || muteWordHits(notification.status, store.rootGetters.mergedConfig.muteWords.value).length > 0
}
export const maybeShowNotification = (store, notification) => {

View file

@ -1,12 +1,14 @@
import { filter } from 'lodash'
const regexStart = '~r/'
const regexEnd = '/'
export const muteWordHits = (status, muteWords) => {
const statusText = status.text.toLowerCase()
const statusSummary = status.summary.toLowerCase()
const hits = filter(muteWords, (muteWord) => {
if (muteWord.startsWith('/') && muteWord.endsWith('/')) {
const muteRegex = new RegExp(muteWord.slice(1, -1))
return muteRegex.test(statusText) || muteRegex.test(statusSummary)
if (muteWord instanceof RegExp) {
return muteWord.test(statusText) || muteWord.test(statusSummary)
}
return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase())
})