feat: content filters (#279)
This commit is contained in:
parent
337d2a8b43
commit
4f8f2ed1f1
14 changed files with 44 additions and 27 deletions
|
@ -1,10 +1,11 @@
|
|||
<script setup lang="ts">
|
||||
import type { Status } from 'masto'
|
||||
import type { Filter, FilterAction, FilterContext, Status } from 'masto'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
status: Status
|
||||
actions?: boolean
|
||||
context?: FilterContext
|
||||
hover?: boolean
|
||||
}>(),
|
||||
{ actions: true },
|
||||
|
@ -43,10 +44,19 @@ function go(evt: MouseEvent | KeyboardEvent) {
|
|||
const createdAt = useFormattedDateTime(status.createdAt)
|
||||
const timeAgoOptions = useTimeAgoOptions(true)
|
||||
const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions)
|
||||
|
||||
// Content Filter logic
|
||||
const filterResult = $computed(() => status.filtered?.length ? status.filtered[0] : null)
|
||||
const filter = $computed(() => filterResult?.filter)
|
||||
|
||||
// a bit of a hack due to Filter being different in v1 and v2
|
||||
// clean up when masto.js supports explicit versions: https://github.com/neet/masto.js/issues/722
|
||||
const filterPhrase = $computed(() => filter?.phrase || (filter as any)?.title)
|
||||
const isFiltered = $computed(() => filterPhrase && (props.context ? filter?.context.includes(props.context) : false))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :id="`status-${status.id}`" ref="el" flex flex-col gap-2 px-4 transition-100 :class="{ 'hover:bg-active': hover }" tabindex="0" focus:outline-none focus-visible:ring="2 primary" @click="onclick" @keydown.enter="onclick">
|
||||
<div v-if="filter?.filterAction !== 'hide'" :id="`status-${status.id}`" ref="el" flex flex-col gap-2 px-4 transition-100 :class="{ 'hover:bg-active': hover }" tabindex="0" focus:outline-none focus-visible:ring="2 primary" @click="onclick" @keydown.enter="onclick">
|
||||
<div v-if="rebloggedBy" pl8>
|
||||
<div flex="~ wrap" gap-1 items-center text-secondary text-sm>
|
||||
<div i-ri:repeat-fill mr-1 />
|
||||
|
@ -83,9 +93,9 @@ const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions)
|
|||
</div>
|
||||
<StatusReplyingTo v-if="status.inReplyToAccountId" :status="status" pt1 />
|
||||
<div :class="status.visibility === 'direct' ? 'my3 p2 px5 br2 bg-fade rounded-3 rounded-tl-none' : ''">
|
||||
<StatusSpoiler :enabled="status.sensitive">
|
||||
<StatusSpoiler :enabled="status.sensitive || isFiltered" :filter="filter?.filterAction">
|
||||
<template #spoiler>
|
||||
<p>{{ status.spoilerText }}</p>
|
||||
<p>{{ filterPhrase ? `${$t('status.filter_hidden_phrase')}: ${filterPhrase}` : status.spoilerText }}</p>
|
||||
</template>
|
||||
<StatusBody :status="status" />
|
||||
<StatusPoll v-if="status.poll" :poll="status.poll" />
|
||||
|
@ -105,4 +115,7 @@ const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions)
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="isFiltered" gap-2 px-4>
|
||||
<p>{{ filterPhrase && `${$t('status.filter_removed_phrase')}: ${filterPhrase}` }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue