forked from Mirrors/elk
feat: filter notifications and conversations
This commit is contained in:
parent
501d422931
commit
28c011ac2e
3 changed files with 28 additions and 7 deletions
|
@ -4,10 +4,23 @@ import type { Paginator, mastodon } from 'masto'
|
||||||
const { paginator } = defineProps<{
|
const { paginator } = defineProps<{
|
||||||
paginator: Paginator<mastodon.v1.Conversation[], mastodon.DefaultPaginationParams>
|
paginator: Paginator<mastodon.v1.Conversation[], mastodon.DefaultPaginationParams>
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
function preprocess(items: mastodon.v1.Conversation[]) {
|
||||||
|
const filteredIndices = items.map(
|
||||||
|
(items, index) => (
|
||||||
|
{
|
||||||
|
status: items.lastStatus,
|
||||||
|
index,
|
||||||
|
}))
|
||||||
|
.filter(item => !!item.status?.filtered?.find(filter => filter.filter.filterAction === 'hide' && filter.filter.context.includes('thread')))
|
||||||
|
.map(item => item.index)
|
||||||
|
|
||||||
|
return items.filter((_, index) => !filteredIndices.includes(index))
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<CommonPaginator :paginator="paginator">
|
<CommonPaginator :paginator="paginator" :preprocess="preprocess">
|
||||||
<template #default="{ item }">
|
<template #default="{ item }">
|
||||||
<ConversationCard
|
<ConversationCard
|
||||||
:conversation="item"
|
:conversation="item"
|
||||||
|
|
|
@ -112,6 +112,19 @@ function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] {
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeFiltered(items: mastodon.v1.Notification[]): mastodon.v1.Notification[] {
|
||||||
|
const filteredIndices = items.map(
|
||||||
|
(items, index) => (
|
||||||
|
{
|
||||||
|
status: items.status,
|
||||||
|
index,
|
||||||
|
}))
|
||||||
|
.filter(item => !!item.status?.filtered?.find(filter => filter.filter.filterAction === 'hide' && filter.filter.context.includes('notifications')))
|
||||||
|
.map(item => item.index)
|
||||||
|
|
||||||
|
return items.filter((_, index) => !filteredIndices.includes(index))
|
||||||
|
}
|
||||||
|
|
||||||
function preprocess(items: NotificationSlot[]): NotificationSlot[] {
|
function preprocess(items: NotificationSlot[]): NotificationSlot[] {
|
||||||
const flattenedNotifications: mastodon.v1.Notification[] = []
|
const flattenedNotifications: mastodon.v1.Notification[] = []
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
@ -131,7 +144,7 @@ function preprocess(items: NotificationSlot[]): NotificationSlot[] {
|
||||||
flattenedNotifications.push(item)
|
flattenedNotifications.push(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return groupItems(flattenedNotifications)
|
return groupItems(removeFiltered(flattenedNotifications))
|
||||||
}
|
}
|
||||||
|
|
||||||
const { clearNotifications } = useNotifications()
|
const { clearNotifications } = useNotifications()
|
||||||
|
|
|
@ -67,10 +67,6 @@ const createdAt = useFormattedDateTime(status.createdAt)
|
||||||
const timeAgoOptions = useTimeAgoOptions(true)
|
const timeAgoOptions = useTimeAgoOptions(true)
|
||||||
const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions)
|
const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions)
|
||||||
|
|
||||||
// Content Filter logic
|
|
||||||
const filterResult = $computed(() => status.filtered?.length ? status.filtered[0] : null)
|
|
||||||
const filter = $computed(() => filterResult?.filter)
|
|
||||||
|
|
||||||
const isSelfReply = $computed(() => status.inReplyToAccountId === status.account.id)
|
const isSelfReply = $computed(() => status.inReplyToAccountId === status.account.id)
|
||||||
const collapseRebloggedBy = $computed(() => rebloggedBy?.id === status.account.id)
|
const collapseRebloggedBy = $computed(() => rebloggedBy?.id === status.account.id)
|
||||||
const isDM = $computed(() => status.visibility === 'direct')
|
const isDM = $computed(() => status.visibility === 'direct')
|
||||||
|
@ -81,7 +77,6 @@ const showReplyTo = $computed(() => !replyToMain && !directReply)
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
v-if="filter?.filterAction !== 'hide'"
|
|
||||||
:id="`status-${status.id}`"
|
:id="`status-${status.id}`"
|
||||||
ref="el"
|
ref="el"
|
||||||
relative flex="~ col gap1" p="l-3 r-4 b-2"
|
relative flex="~ col gap1" p="l-3 r-4 b-2"
|
||||||
|
|
Loading…
Reference in a new issue