about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHailey <153161762+haileyok@users.noreply.github.com>2024-01-30 16:55:46 -0800
committerGitHub <noreply@github.com>2024-01-30 16:55:46 -0800
commitca9b2a551da9e56c02846c23f73816a0a8267006 (patch)
treef2f17955f4f4d4a01fb5bbfe1be40bc99aff0617 /src
parent08a11f628ea27b20262c156f2a36c42bb763c5f1 (diff)
downloadvoidsky-ca9b2a551da9e56c02846c23f73816a0a8267006.tar.zst
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
Diffstat (limited to 'src')
-rw-r--r--src/state/queries/notifications/util.ts47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts
index 411a0f791..e53a07258 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
 }