added option to make filter case-sensitive
This commit is contained in:
parent
7c593e4898
commit
085fa28e3e
5 changed files with 56 additions and 13 deletions
|
|
@ -58,6 +58,7 @@ const FilteringTab = {
|
|||
hide = false,
|
||||
name = '',
|
||||
value = '',
|
||||
caseSensitive = false,
|
||||
} = data
|
||||
|
||||
this.createFilter({
|
||||
|
|
@ -66,6 +67,7 @@ const FilteringTab = {
|
|||
hide,
|
||||
name,
|
||||
value,
|
||||
caseSensitive,
|
||||
})
|
||||
},
|
||||
onImportFailure(result) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,16 @@
|
|||
text-align: right;
|
||||
}
|
||||
|
||||
> label.checkbox {
|
||||
display: grid;
|
||||
grid-template-columns: subgrid;
|
||||
grid-template-rows: subgrid;
|
||||
grid-column: 1 / span 2;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.filter-field-value {
|
||||
display: flex;
|
||||
grid-column: 2 / span 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -254,6 +254,20 @@
|
|||
:value="filter[1].value"
|
||||
@input="updateFilter(filter[0], 'value', $event.target.value)"
|
||||
>
|
||||
{{ ' ' }}
|
||||
</div>
|
||||
<div class="filter-value filter-field">
|
||||
<Checkbox
|
||||
:id="'filterCaseSensitive' + filter[0]"
|
||||
:model-value="filter[1].caseSensitive"
|
||||
:name="'filterCaseSensitive' + filter[0]"
|
||||
class="input-inset input-boolean case-sensitive"
|
||||
@update:model-value="updateFilter(filter[0], 'caseSensitive', $event)"
|
||||
>
|
||||
<template #before>
|
||||
{{ $t('settings.filter.case_sensitive') }}
|
||||
</template>
|
||||
</Checkbox>
|
||||
</div>
|
||||
<div class="filter-expires filter-field">
|
||||
<label
|
||||
|
|
|
|||
|
|
@ -440,6 +440,7 @@
|
|||
"plain": "Simple",
|
||||
"user": "User (Simple)",
|
||||
"user_regexp": "User (RegExp)",
|
||||
"case_sensitive": "Case-sensitive",
|
||||
"hide": "Hide completely",
|
||||
"name": "Name",
|
||||
"value": "Value",
|
||||
|
|
|
|||
|
|
@ -10,24 +10,32 @@ export const muteFilterHits = (muteFilters, status) => {
|
|||
return muteFilters
|
||||
.toSorted((a, b) => b.order - a.order)
|
||||
.map((filter) => {
|
||||
const { hide, expires, name, value, type, enabled } = filter
|
||||
const { hide, expires, name, value, type, enabled, caseSensitive = false } = filter
|
||||
if (!enabled) return false
|
||||
if (value === '') return false
|
||||
if (expires !== null && expires < Date.now()) return false
|
||||
switch (type) {
|
||||
case 'word': {
|
||||
const lowercaseValue = value.toLowerCase()
|
||||
if (
|
||||
statusText.toLowerCase().includes(lowercaseValue) ||
|
||||
statusSummary.toLowerCase().includes(lowercaseValue)
|
||||
) {
|
||||
let match = false
|
||||
if (caseSensitive) {
|
||||
match =
|
||||
statusText.includes(value) ||
|
||||
statusSummary.includes(value)
|
||||
} else {
|
||||
const lowercaseValue = value.toLowerCase()
|
||||
match =
|
||||
statusText.toLowerCase().includes(lowercaseValue) ||
|
||||
statusSummary.toLowerCase().includes(lowercaseValue)
|
||||
}
|
||||
|
||||
if (match) {
|
||||
return { hide, name }
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'regexp': {
|
||||
try {
|
||||
const re = new RegExp(value, 'i')
|
||||
const re = new RegExp(value, caseSensitive ? '' : 'i')
|
||||
if (re.test(statusText) || re.test(statusSummary)) {
|
||||
return { hide, name }
|
||||
}
|
||||
|
|
@ -37,18 +45,27 @@ export const muteFilterHits = (muteFilters, status) => {
|
|||
}
|
||||
}
|
||||
case 'user': {
|
||||
if (
|
||||
poster.includes(value) ||
|
||||
replyToUser.includes(value) ||
|
||||
mentions.some((mention) => mention.includes(value))
|
||||
) {
|
||||
let match = false
|
||||
if (caseSensitive) {
|
||||
match =
|
||||
poster.includes(value) ||
|
||||
replyToUser.includes(value) ||
|
||||
mentions.some((mention) => mention.includes(value))
|
||||
} else {
|
||||
const lowercaseValue = value.toLowerCase()
|
||||
match =
|
||||
poster.toLowerCase().includes(lowercaseValue) ||
|
||||
replyToUser.toLowerCase().includes(lowercaseValue) ||
|
||||
mentions.some((mention) => mention.toLowerCase().includes(lowercaseValue))
|
||||
}
|
||||
if (match) {
|
||||
return { hide, name }
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'user_regexp': {
|
||||
try {
|
||||
const re = new RegExp(value, 'i')
|
||||
const re = new RegExp(value, caseSensitive ? '' : 'i')
|
||||
if (
|
||||
re.test(poster) ||
|
||||
re.test(replyToUser) ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue