check if a thread is muted before incrementing notif badge, filter out quotes (#2686)

* check if a thread is muted before incrementing notif badge

* some filtering for quotes and reposts

* move logic to util

* change logic

* revert always fetching

* logic for cases when we don't have a subject (count)

* unneeded change

* check subject embed in `isThreadMuted`

* remove todo
This commit is contained in:
Hailey 2024-01-30 16:55:46 -08:00 committed by GitHub
parent 08a11f628e
commit ca9b2a551d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,7 @@ import {
AppBskyFeedPost, AppBskyFeedPost,
AppBskyFeedRepost, AppBskyFeedRepost,
AppBskyFeedLike, AppBskyFeedLike,
AppBskyEmbedRecord,
} from '@atproto/api' } from '@atproto/api'
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped' import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
import chunk from 'lodash.chunk' import chunk from 'lodash.chunk'
@ -110,8 +111,6 @@ function shouldFilterNotif(
return true return true
} }
} }
// TODO: thread muting is not being applied
// (this requires fetching the post)
return false return false
} }
@ -221,10 +220,44 @@ function getSubjectUri(
} }
} }
function isThreadMuted(notif: FeedNotification, mutes: string[]): boolean { export function isThreadMuted(notif: FeedNotification, threadMutes: string[]) {
if (!notif.subject) { // If there's a subject we want to use that. This will always work on the notifications tab
return false 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
} }