[🐴] don't include blocked convos in unread count (#4082)
* 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 <git@esb.lol>zio/stable
parent
dd0f57e3e3
commit
f42f7fa035
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
Loading…
Reference in New Issue