From f42f7fa0353a45c6b20e65e1a54b64e1c28b0cd5 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 17 May 2024 20:46:01 +0100 Subject: [PATCH] =?UTF-8?q?[=F0=9F=90=B4]=20don't=20include=20blocked=20co?= =?UTF-8?q?nvos=20in=20unread=20count=20(#4082)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * don't include blocked convos in unread count * Use moderateProfile * Handle blocked state in chat list * Fix logic formatting, add todo --------- Co-authored-by: Eric Bailey --- src/screens/Messages/List/ChatListItem.tsx | 12 ++++++---- .../queries/messages/list-converations.ts | 24 ++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/screens/Messages/List/ChatListItem.tsx b/src/screens/Messages/List/ChatListItem.tsx index 0a0f8c57..a7b7e068 100644 --- a/src/screens/Messages/List/ChatListItem.tsx +++ b/src/screens/Messages/List/ChatListItem.tsx @@ -169,7 +169,7 @@ function ChatListItemReady({ )} )} - {convo.muted && ( + {(convo.muted || moderation.blocked) && ( 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} @@ -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 4b4d50c4..3939ab8e 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(() => {