[🐴] 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>
This commit is contained in:
		
							parent
							
								
									dd0f57e3e3
								
							
						
					
					
						commit
						f42f7fa035
					
				
					 2 changed files with 28 additions and 8 deletions
				
			
		|  | @ -169,7 +169,7 @@ function ChatListItemReady({ | ||||||
|                       )} |                       )} | ||||||
|                     </TimeElapsed> |                     </TimeElapsed> | ||||||
|                   )} |                   )} | ||||||
|                   {convo.muted && ( |                   {(convo.muted || moderation.blocked) && ( | ||||||
|                     <Text |                     <Text | ||||||
|                       style={[ |                       style={[ | ||||||
|                         a.text_sm, |                         a.text_sm, | ||||||
|  | @ -200,7 +200,8 @@ function ChatListItemReady({ | ||||||
|                     convo.unreadCount > 0 |                     convo.unreadCount > 0 | ||||||
|                       ? a.font_bold |                       ? a.font_bold | ||||||
|                       : t.atoms.text_contrast_high, |                       : t.atoms.text_contrast_high, | ||||||
|                     convo.muted && t.atoms.text_contrast_medium, |                     (convo.muted || moderation.blocked) && | ||||||
|  |                       t.atoms.text_contrast_medium, | ||||||
|                   ]}> |                   ]}> | ||||||
|                   {lastMessage} |                   {lastMessage} | ||||||
|                 </Text> |                 </Text> | ||||||
|  | @ -211,9 +212,10 @@ function ChatListItemReady({ | ||||||
|                     a.absolute, |                     a.absolute, | ||||||
|                     a.rounded_full, |                     a.rounded_full, | ||||||
|                     { |                     { | ||||||
|                       backgroundColor: convo.muted |                       backgroundColor: | ||||||
|                         ? t.palette.contrast_200 |                         convo.muted || moderation.blocked | ||||||
|                         : t.palette.primary_500, |                           ? t.palette.contrast_200 | ||||||
|  |                           : t.palette.primary_500, | ||||||
|                       height: 7, |                       height: 7, | ||||||
|                       width: 7, |                       width: 7, | ||||||
|                     }, |                     }, | ||||||
|  |  | ||||||
|  | @ -1,5 +1,9 @@ | ||||||
| import {useCallback, useMemo} from 'react' | import {useCallback, useMemo} from 'react' | ||||||
| import {ChatBskyConvoDefs, ChatBskyConvoListConvos} from '@atproto/api' | import { | ||||||
|  |   ChatBskyConvoDefs, | ||||||
|  |   ChatBskyConvoListConvos, | ||||||
|  |   moderateProfile, | ||||||
|  | } from '@atproto/api' | ||||||
| import { | import { | ||||||
|   InfiniteData, |   InfiniteData, | ||||||
|   QueryClient, |   QueryClient, | ||||||
|  | @ -8,8 +12,9 @@ import { | ||||||
| } from '@tanstack/react-query' | } from '@tanstack/react-query' | ||||||
| 
 | 
 | ||||||
| import {useCurrentConvoId} from '#/state/messages/current-convo-id' | 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 {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' | import {decrementBadgeCount} from 'lib/notifications/notifications' | ||||||
| 
 | 
 | ||||||
| export const RQKEY = ['convo-list'] | export const RQKEY = ['convo-list'] | ||||||
|  | @ -36,16 +41,29 @@ export function useListConvos({refetchInterval}: {refetchInterval: number}) { | ||||||
| 
 | 
 | ||||||
| export function useUnreadMessageCount() { | export function useUnreadMessageCount() { | ||||||
|   const {currentConvoId} = useCurrentConvoId() |   const {currentConvoId} = useCurrentConvoId() | ||||||
|  |   const {currentAccount} = useSession() | ||||||
|   const convos = useListConvos({ |   const convos = useListConvos({ | ||||||
|     refetchInterval: 30_000, |     refetchInterval: 30_000, | ||||||
|   }) |   }) | ||||||
|  |   const moderationOpts = useModerationOpts() | ||||||
| 
 | 
 | ||||||
|   const count = |   const count = | ||||||
|     convos.data?.pages |     convos.data?.pages | ||||||
|       .flatMap(page => page.convos) |       .flatMap(page => page.convos) | ||||||
|       .filter(convo => convo.id !== currentConvoId) |       .filter(convo => convo.id !== currentConvoId) | ||||||
|       .reduce((acc, convo) => { |       .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 |       }, 0) ?? 0 | ||||||
| 
 | 
 | ||||||
|   return useMemo(() => { |   return useMemo(() => { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue