forked from Mirrors/elk
fix: filter and cw logic (#1633)
This commit is contained in:
parent
a1b2da3d5e
commit
0fbe34c1e8
4 changed files with 42 additions and 16 deletions
|
@ -6,7 +6,8 @@ const { paginator } = defineProps<{
|
|||
}>()
|
||||
|
||||
function preprocess(items: mastodon.v1.Conversation[]): mastodon.v1.Conversation[] {
|
||||
return items.filter(items => !items.lastStatus?.filtered?.find(
|
||||
const isAuthored = (conversation: mastodon.v1.Conversation) => conversation.lastStatus ? conversation.lastStatus.account.id === currentUser.value?.account.id : false
|
||||
return items.filter(item => isAuthored(item) || !item.lastStatus?.filtered?.find(
|
||||
filter => filter.filter.filterAction === 'hide' && filter.filter.context.includes('thread'),
|
||||
))
|
||||
}
|
||||
|
|
|
@ -15,7 +15,11 @@ const filterResult = $computed(() => status.filtered?.length ? status.filtered[0
|
|||
const filter = $computed(() => filterResult?.filter)
|
||||
|
||||
const filterPhrase = $computed(() => filter?.title)
|
||||
const isFiltered = $computed(() => filterPhrase && (context && context !== 'details' ? filter?.context.includes(context) : false))
|
||||
const isFiltered = $computed(() => status.account.id !== currentUser.value?.account.id && filterPhrase && context && context !== 'details' && !!filter?.context.includes(context))
|
||||
|
||||
// check spoiler text or media attachment
|
||||
// needed to handle accounts that mark all their posts as sensitive
|
||||
const hasSensitiveSpoilerOrMedia = $computed(() => status.sensitive && (!!status.spoilerText || !!status.mediaAttachments.length))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -27,13 +31,13 @@ const isFiltered = $computed(() => filterPhrase && (context && context !== 'deta
|
|||
}"
|
||||
>
|
||||
<StatusBody v-if="!isFiltered && status.sensitive && !status.spoilerText" :status="status" :newer="newer" :with-action="!isDetails" :class="isDetails ? 'text-xl' : ''" />
|
||||
<StatusSpoiler :enabled="status.sensitive || isFiltered" :filter="isFiltered" :is-d-m="isDM">
|
||||
<template v-if="filterPhrase" #spoiler>
|
||||
<p>{{ `${$t('status.filter_hidden_phrase')}: ${filterPhrase}` }}</p>
|
||||
</template>
|
||||
<template v-else-if="status.spoilerText" #spoiler>
|
||||
<StatusSpoiler :enabled="hasSensitiveSpoilerOrMedia || isFiltered" :filter="isFiltered" :is-d-m="isDM">
|
||||
<template v-if="status.spoilerText" #spoiler>
|
||||
<p>{{ status.spoilerText }}</p>
|
||||
</template>
|
||||
<template v-else-if="filterPhrase" #spoiler>
|
||||
<p>{{ `${$t('status.filter_hidden_phrase')}: ${filterPhrase}` }}</p>
|
||||
</template>
|
||||
<StatusBody v-if="!status.sensitive || status.spoilerText" :status="status" :newer="newer" :with-action="!isDetails" :class="isDetails ? 'text-xl' : ''" />
|
||||
<StatusTranslation :status="status" />
|
||||
<StatusPoll v-if="status.poll" :status="status" />
|
||||
|
|
|
@ -11,7 +11,7 @@ function areStatusesConsecutive(a: mastodon.v1.Status, b: mastodon.v1.Status) {
|
|||
|
||||
function removeFilteredItems(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext): mastodon.v1.Status[] {
|
||||
const isStrict = (filter: mastodon.v1.FilterResult) => filter.filter.filterAction === 'hide' && filter.filter.context.includes(context)
|
||||
const isFiltered = (item: mastodon.v1.Status) => !item.filtered?.find(isStrict)
|
||||
const isFiltered = (item: mastodon.v1.Status) => (item.account.id === currentUser.value?.account.id) || !item.filtered?.find(isStrict)
|
||||
const isReblogFiltered = (item: mastodon.v1.Status) => !item.reblog?.filtered?.find(isStrict)
|
||||
|
||||
return [...items].filter(isFiltered).filter(isReblogFiltered)
|
||||
|
|
|
@ -1,28 +1,49 @@
|
|||
/** @vitest-environment happy-dom */
|
||||
|
||||
import type { mastodon } from 'masto'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
function status(id: string, filtered?: mastodon.v1.FilterContext): mastodon.v1.Status {
|
||||
if (filtered) {
|
||||
return {
|
||||
const fakeStatus = {
|
||||
id,
|
||||
filtered: [
|
||||
account: {
|
||||
id: 'FAKE ID',
|
||||
} as mastodon.v1.Account,
|
||||
} as mastodon.v1.Status
|
||||
|
||||
if (filtered) {
|
||||
fakeStatus.filtered
|
||||
= [
|
||||
{
|
||||
filter: {
|
||||
filterAction: 'hide',
|
||||
context: [filtered],
|
||||
},
|
||||
} as mastodon.v1.FilterResult,
|
||||
],
|
||||
} as mastodon.v1.Status
|
||||
]
|
||||
}
|
||||
|
||||
return { id } as mastodon.v1.Status
|
||||
return fakeStatus
|
||||
}
|
||||
|
||||
function reply(id: string, s: mastodon.v1.Status) {
|
||||
return { id, inReplyToId: s.id } as mastodon.v1.Status
|
||||
return {
|
||||
id,
|
||||
account: {
|
||||
id: 'FAKE ID',
|
||||
} as mastodon.v1.Account,
|
||||
inReplyToId: s.id,
|
||||
} as mastodon.v1.Status
|
||||
}
|
||||
|
||||
function reblog(id: string, s: mastodon.v1.Status) {
|
||||
return { id, reblog: s } as mastodon.v1.Status
|
||||
return {
|
||||
id,
|
||||
account: {
|
||||
id: 'FAKE ID',
|
||||
} as mastodon.v1.Account,
|
||||
reblog: s,
|
||||
} as mastodon.v1.Status
|
||||
}
|
||||
|
||||
const p_a1 = status('p_a1')
|
||||
|
|
Loading…
Reference in a new issue