Move regex creation to filtering tab logic
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
This commit is contained in:
parent
105154a42b
commit
ef6f8586c2
4 changed files with 25 additions and 8 deletions
|
@ -1,14 +1,17 @@
|
||||||
import { filter, trim, debounce } from 'lodash'
|
import { debounce } from 'lodash'
|
||||||
import BooleanSetting from '../helpers/boolean_setting.vue'
|
import BooleanSetting from '../helpers/boolean_setting.vue'
|
||||||
import ChoiceSetting from '../helpers/choice_setting.vue'
|
import ChoiceSetting from '../helpers/choice_setting.vue'
|
||||||
import IntegerSetting from '../helpers/integer_setting.vue'
|
import IntegerSetting from '../helpers/integer_setting.vue'
|
||||||
|
|
||||||
import SharedComputedObject from '../helpers/shared_computed_object.js'
|
import SharedComputedObject from '../helpers/shared_computed_object.js'
|
||||||
|
|
||||||
|
const regexStart = '~r/'
|
||||||
|
const regexEnd = '/'
|
||||||
|
|
||||||
const FilteringTab = {
|
const FilteringTab = {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
muteWordsStringLocal: this.$store.getters.mergedConfig.muteWords.join('\n'),
|
muteWordsStringLocal: this.$store.getters.mergedConfig.muteWords.raw,
|
||||||
replyVisibilityOptions: ['all', 'following', 'self'].map(mode => ({
|
replyVisibilityOptions: ['all', 'following', 'self'].map(mode => ({
|
||||||
key: mode,
|
key: mode,
|
||||||
value: mode,
|
value: mode,
|
||||||
|
@ -31,7 +34,19 @@ const FilteringTab = {
|
||||||
this.muteWordsStringLocal = value
|
this.muteWordsStringLocal = value
|
||||||
this.$store.dispatch('setOption', {
|
this.$store.dispatch('setOption', {
|
||||||
name: 'muteWords',
|
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)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ const Status = {
|
||||||
computed: {
|
computed: {
|
||||||
...controlledOrUncontrolledGetters(['replying', 'quoting', 'mediaPlaying']),
|
...controlledOrUncontrolledGetters(['replying', 'quoting', 'mediaPlaying']),
|
||||||
muteWords () {
|
muteWords () {
|
||||||
return this.mergedConfig.muteWords
|
return this.mergedConfig.muteWords.value
|
||||||
},
|
},
|
||||||
showReasonMutedThread () {
|
showReasonMutedThread () {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -48,7 +48,7 @@ const sortById = (a, b) => {
|
||||||
|
|
||||||
const isMutedNotification = (store, notification) => {
|
const isMutedNotification = (store, notification) => {
|
||||||
if (!notification.status) return
|
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) => {
|
export const maybeShowNotification = (store, notification) => {
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import { filter } from 'lodash'
|
import { filter } from 'lodash'
|
||||||
|
|
||||||
|
const regexStart = '~r/'
|
||||||
|
const regexEnd = '/'
|
||||||
|
|
||||||
export const muteWordHits = (status, muteWords) => {
|
export const muteWordHits = (status, muteWords) => {
|
||||||
const statusText = status.text.toLowerCase()
|
const statusText = status.text.toLowerCase()
|
||||||
const statusSummary = status.summary.toLowerCase()
|
const statusSummary = status.summary.toLowerCase()
|
||||||
const hits = filter(muteWords, (muteWord) => {
|
const hits = filter(muteWords, (muteWord) => {
|
||||||
if (muteWord.startsWith('/') && muteWord.endsWith('/')) {
|
if (muteWord instanceof RegExp) {
|
||||||
const muteRegex = new RegExp(muteWord.slice(1, -1))
|
return muteWord.test(statusText) || muteWord.test(statusSummary)
|
||||||
return muteRegex.test(statusText) || muteRegex.test(statusSummary)
|
|
||||||
}
|
}
|
||||||
return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase())
|
return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase())
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue