[🐴] Invalidate list convos query on block (#4171)
* more memoization * invalidate listconvos query on blockzio/stable
parent
b937372325
commit
3ca41e4efb
|
@ -46,27 +46,29 @@ export function useUnreadMessageCount() {
|
||||||
})
|
})
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
|
|
||||||
const count =
|
const count = useMemo(() => {
|
||||||
convos.data?.pages
|
return (
|
||||||
.flatMap(page => page.convos)
|
convos.data?.pages
|
||||||
.filter(convo => convo.id !== currentConvoId)
|
.flatMap(page => page.convos)
|
||||||
.reduce((acc, convo) => {
|
.filter(convo => convo.id !== currentConvoId)
|
||||||
const otherMember = convo.members.find(
|
.reduce((acc, convo) => {
|
||||||
member => member.did !== currentAccount?.did,
|
const otherMember = convo.members.find(
|
||||||
)
|
member => member.did !== currentAccount?.did,
|
||||||
|
)
|
||||||
|
|
||||||
if (!otherMember || !moderationOpts) return acc
|
if (!otherMember || !moderationOpts) return acc
|
||||||
|
|
||||||
// TODO could shadow this outside this hook and get optimistic block state
|
const moderation = moderateProfile(otherMember, moderationOpts)
|
||||||
const moderation = moderateProfile(otherMember, moderationOpts)
|
const shouldIgnore =
|
||||||
const shouldIgnore =
|
convo.muted ||
|
||||||
convo.muted ||
|
moderation.blocked ||
|
||||||
moderation.blocked ||
|
otherMember.did === 'missing.invalid'
|
||||||
otherMember.did === 'missing.invalid'
|
const unreadCount = !shouldIgnore && convo.unreadCount > 0 ? 1 : 0
|
||||||
const unreadCount = !shouldIgnore && convo.unreadCount > 0 ? 1 : 0
|
|
||||||
|
|
||||||
return acc + unreadCount
|
return acc + unreadCount
|
||||||
}, 0) ?? 0
|
}, 0) ?? 0
|
||||||
|
)
|
||||||
|
}, [convos.data, currentAccount?.did, currentConvoId, moderationOpts])
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import {STALE} from '#/state/queries'
|
||||||
import {resetProfilePostsQueries} from '#/state/queries/post-feed'
|
import {resetProfilePostsQueries} from '#/state/queries/post-feed'
|
||||||
import {updateProfileShadow} from '../cache/profile-shadow'
|
import {updateProfileShadow} from '../cache/profile-shadow'
|
||||||
import {useAgent, useSession} from '../session'
|
import {useAgent, useSession} from '../session'
|
||||||
|
import {RQKEY as RQKEY_LIST_CONVOS} from './messages/list-converations'
|
||||||
import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'
|
import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'
|
||||||
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
|
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
|
||||||
|
|
||||||
|
@ -414,6 +415,7 @@ export function useProfileBlockMutationQueue(
|
||||||
updateProfileShadow(queryClient, did, {
|
updateProfileShadow(queryClient, did, {
|
||||||
blockingUri: finalBlockingUri,
|
blockingUri: finalBlockingUri,
|
||||||
})
|
})
|
||||||
|
queryClient.invalidateQueries({queryKey: RQKEY_LIST_CONVOS})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue