diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts index 411a0f79..e53a0725 100644 --- a/src/state/queries/notifications/util.ts +++ b/src/state/queries/notifications/util.ts @@ -6,6 +6,7 @@ import { AppBskyFeedPost, AppBskyFeedRepost, AppBskyFeedLike, + AppBskyEmbedRecord, } from '@atproto/api' import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped' import chunk from 'lodash.chunk' @@ -110,8 +111,6 @@ function shouldFilterNotif( return true } } - // TODO: thread muting is not being applied - // (this requires fetching the post) return false } @@ -221,10 +220,44 @@ function getSubjectUri( } } -function isThreadMuted(notif: FeedNotification, mutes: string[]): boolean { - if (!notif.subject) { - return false +export function isThreadMuted(notif: FeedNotification, threadMutes: string[]) { + // If there's a subject we want to use that. This will always work on the notifications tab + if (notif.subject) { + const record = notif.subject.record as AppBskyFeedPost.Record + // Check for a quote record + if ( + (record.reply && threadMutes.includes(record.reply.root.uri)) || + (notif.subject.uri && threadMutes.includes(notif.subject.uri)) + ) { + return true + } else if ( + AppBskyEmbedRecord.isMain(record.embed) && + threadMutes.includes(record.embed.record.uri) + ) { + return true + } + } else { + // Otherwise we just do the best that we can + const record = notif.notification.record + if (AppBskyFeedPost.isRecord(record)) { + if (record.reply && threadMutes.includes(record.reply.root.uri)) { + // We can always filter replies + return true + } else if ( + AppBskyEmbedRecord.isMain(record.embed) && + threadMutes.includes(record.embed.record.uri) + ) { + // We can also filter quotes if the quoted post is the root + return true + } + } else if ( + AppBskyFeedRepost.isRecord(record) && + threadMutes.includes(record.subject.uri) + ) { + // Finally we can filter reposts, again if the post is the root + return true + } } - const record = notif.subject.record as AppBskyFeedPost.Record // assured in fetchSubjects() - return mutes.includes(record.reply?.root.uri || notif.subject.uri) + + return false }