From ef6f8586c2cf731a9ddfcfb02e5e7e6bb92d084f Mon Sep 17 00:00:00 2001 From: Norm Date: Wed, 18 Dec 2024 22:45:05 -0500 Subject: [PATCH] Move regex creation to filtering tab logic --- .../settings_modal/tabs/filtering_tab.js | 21 ++++++++++++++++--- src/components/status/status.js | 2 +- .../notification_utils/notification_utils.js | 2 +- src/services/status_parser/status_parser.js | 8 ++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/components/settings_modal/tabs/filtering_tab.js b/src/components/settings_modal/tabs/filtering_tab.js index d3bb40c3..e2459e50 100644 --- a/src/components/settings_modal/tabs/filtering_tab.js +++ b/src/components/settings_modal/tabs/filtering_tab.js @@ -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) } diff --git a/src/components/status/status.js b/src/components/status/status.js index 9bb3364f..5b562570 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -170,7 +170,7 @@ const Status = { computed: { ...controlledOrUncontrolledGetters(['replying', 'quoting', 'mediaPlaying']), muteWords () { - return this.mergedConfig.muteWords + return this.mergedConfig.muteWords.value }, showReasonMutedThread () { return ( diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index fc5b4d8b..e818f399 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -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) => { diff --git a/src/services/status_parser/status_parser.js b/src/services/status_parser/status_parser.js index 9647ab44..355b8c97 100644 --- a/src/services/status_parser/status_parser.js +++ b/src/services/status_parser/status_parser.js @@ -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()) })