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 todozio/stable
parent
08a11f628e
commit
ca9b2a551d
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue