about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/screens/Messages/List/ChatListItem.tsx12
-rw-r--r--src/state/queries/messages/list-converations.ts24
2 files changed, 28 insertions, 8 deletions
diff --git a/src/screens/Messages/List/ChatListItem.tsx b/src/screens/Messages/List/ChatListItem.tsx
index 0a0f8c575..a7b7e0680 100644
--- a/src/screens/Messages/List/ChatListItem.tsx
+++ b/src/screens/Messages/List/ChatListItem.tsx
@@ -169,7 +169,7 @@ function ChatListItemReady({
                       )}
                     </TimeElapsed>
                   )}
-                  {convo.muted && (
+                  {(convo.muted || moderation.blocked) && (
                     <Text
                       style={[
                         a.text_sm,
@@ -200,7 +200,8 @@ function ChatListItemReady({
                     convo.unreadCount > 0
                       ? a.font_bold
                       : t.atoms.text_contrast_high,
-                    convo.muted && t.atoms.text_contrast_medium,
+                    (convo.muted || moderation.blocked) &&
+                      t.atoms.text_contrast_medium,
                   ]}>
                   {lastMessage}
                 </Text>
@@ -211,9 +212,10 @@ function ChatListItemReady({
                     a.absolute,
                     a.rounded_full,
                     {
-                      backgroundColor: convo.muted
-                        ? t.palette.contrast_200
-                        : t.palette.primary_500,
+                      backgroundColor:
+                        convo.muted || moderation.blocked
+                          ? t.palette.contrast_200
+                          : t.palette.primary_500,
                       height: 7,
                       width: 7,
                     },
diff --git a/src/state/queries/messages/list-converations.ts b/src/state/queries/messages/list-converations.ts
index 4b4d50c49..3939ab8e3 100644
--- a/src/state/queries/messages/list-converations.ts
+++ b/src/state/queries/messages/list-converations.ts
@@ -1,5 +1,9 @@
 import {useCallback, useMemo} from 'react'
-import {ChatBskyConvoDefs, ChatBskyConvoListConvos} from '@atproto/api'
+import {
+  ChatBskyConvoDefs,
+  ChatBskyConvoListConvos,
+  moderateProfile,
+} from '@atproto/api'
 import {
   InfiniteData,
   QueryClient,
@@ -8,8 +12,9 @@ import {
 } from '@tanstack/react-query'
 
 import {useCurrentConvoId} from '#/state/messages/current-convo-id'
+import {useModerationOpts} from '#/state/preferences/moderation-opts'
 import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
-import {useAgent} from '#/state/session'
+import {useAgent, useSession} from '#/state/session'
 import {decrementBadgeCount} from 'lib/notifications/notifications'
 
 export const RQKEY = ['convo-list']
@@ -36,16 +41,29 @@ export function useListConvos({refetchInterval}: {refetchInterval: number}) {
 
 export function useUnreadMessageCount() {
   const {currentConvoId} = useCurrentConvoId()
+  const {currentAccount} = useSession()
   const convos = useListConvos({
     refetchInterval: 30_000,
   })
+  const moderationOpts = useModerationOpts()
 
   const count =
     convos.data?.pages
       .flatMap(page => page.convos)
       .filter(convo => convo.id !== currentConvoId)
       .reduce((acc, convo) => {
-        return acc + (!convo.muted && convo.unreadCount > 0 ? 1 : 0)
+        const otherMember = convo.members.find(
+          member => member.did !== currentAccount?.did,
+        )
+
+        if (!otherMember || !moderationOpts) return acc
+
+        // TODO could shadow this outside this hook and get optimistic block state
+        const moderation = moderateProfile(otherMember, moderationOpts)
+        const shouldIgnore = convo.muted || moderation.blocked
+        const unreadCount = !shouldIgnore && convo.unreadCount > 0 ? 1 : 0
+
+        return acc + unreadCount
       }, 0) ?? 0
 
   return useMemo(() => {