1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Partial fix of #444

It is possible to implement what the web does but that adds additional resources which I believe is not justified. Filtering is meant to be precise. Even hiding the entire block that you still would like to take a look at the content, then why would you set up a certain filter then.

Though showing the matched filter is still useful.
This commit is contained in:
xmflsct
2022-11-11 23:46:22 +01:00
parent 72917c21f6
commit 1ae7cc7038
4 changed files with 32 additions and 62 deletions

View File

@ -10,7 +10,7 @@ import { useTranslation } from 'react-i18next'
import { View } from 'react-native'
const TimelineFiltered = React.memo(
() => {
({ phrase }: { phrase: string }) => {
const { colors } = useTheme()
const { t } = useTranslation('componentTimeline')
@ -25,7 +25,7 @@ const TimelineFiltered = React.memo(
paddingLeft: StyleConstants.Avatar.M + StyleConstants.Spacing.S
}}
>
{t('shared.filtered')}
{t('shared.filtered', { phrase })}
</CustomText>
</View>
)
@ -44,34 +44,29 @@ export const shouldFilter = ({
}>
status: Mastodon.Status
queryKey: QueryKeyTimeline
}) => {
}): string | null => {
const instance = getInstance(store.getState())
const ownAccount =
getInstanceAccount(store.getState())?.id === status.account?.id
const ownAccount = getInstanceAccount(store.getState())?.id === status.account?.id
let shouldFilter = false
let shouldFilter: string | null = null
if (!ownAccount) {
const parser = new htmlparser2.Parser({
ontext: (text: string) => {
if (!copiableContent.current.complete) {
copiableContent.current.content =
copiableContent.current.content + text
copiableContent.current.content = copiableContent.current.content + text
}
const checkFilter = (filter: Mastodon.Filter) => {
const escapedPhrase = filter.phrase.replace(
/[.*+?^${}()|[\]\\]/g,
'\\$&'
) // $& means the whole matched string
const escapedPhrase = filter.phrase.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
switch (filter.whole_word) {
case true:
if (new RegExp('\\b' + escapedPhrase + '\\b').test(text)) {
shouldFilter = true
shouldFilter = filter.phrase
}
break
case false:
if (new RegExp(escapedPhrase).test(text)) {
shouldFilter = true
shouldFilter = filter.phrase
}
break
}