Bluesky app fork with some witchin' additions 💫

Rework variable naming, logic for rendering chat requests (#8737)

authored by hailey.at and committed by

GitHub fade51e9 d4b23d3a

+28 -34
+26 -30
src/screens/Messages/ChatList.tsx
··· 55 55 function renderItem({item}: {item: ListItem}) { 56 56 switch (item.type) { 57 57 case 'INBOX': 58 - return <InboxPreview count={item.count} profiles={item.profiles} /> 58 + return <InboxPreview profiles={item.profiles} /> 59 59 case 'CONVERSATION': 60 60 return <ChatListItem convo={item.conversation} /> 61 61 } ··· 140 140 141 141 const leftConvos = useLeftConvos() 142 142 143 - const inboxPreviewConvos = useMemo(() => { 144 - const inbox = 145 - inboxData?.pages 146 - .flatMap(page => page.convos) 147 - .filter( 148 - convo => 149 - !leftConvos.includes(convo.id) && 150 - !convo.muted && 151 - convo.unreadCount > 0 && 152 - convo.members.every(member => member.handle !== 'missing.invalid'), 153 - ) ?? [] 143 + const inboxAllConvos = 144 + inboxData?.pages 145 + .flatMap(page => page.convos) 146 + .filter( 147 + convo => 148 + !leftConvos.includes(convo.id) && 149 + !convo.muted && 150 + convo.members.every(member => member.handle !== 'missing.invalid'), 151 + ) ?? [] 152 + const hasInboxConvos = inboxAllConvos?.length > 0 154 153 155 - return inbox 156 - .map(x => x.members.find(y => y.did !== currentAccount?.did)) 157 - .filter(x => !!x) 158 - }, [inboxData, leftConvos, currentAccount?.did]) 154 + const inboxUnreadConvos = inboxAllConvos.filter( 155 + convo => convo.unreadCount > 0, 156 + ) 157 + 158 + const inboxUnreadConvoMembers = inboxUnreadConvos 159 + .map(x => x.members.find(y => y.did !== currentAccount?.did)) 160 + .filter(x => !!x) 159 161 160 162 const conversations = useMemo(() => { 161 163 if (data?.pages) { ··· 163 165 .flatMap(page => page.convos) 164 166 // filter out convos that are actively being left 165 167 .filter(convo => !leftConvos.includes(convo.id)) 166 - 167 - const hasInboxRequests = inboxPreviewConvos?.length > 0 168 168 169 169 return [ 170 - ...(hasInboxRequests 170 + ...(hasInboxConvos 171 171 ? [ 172 172 { 173 173 type: 'INBOX' as const, 174 - count: inboxPreviewConvos.length, 175 - profiles: inboxPreviewConvos.slice(0, 3), 174 + count: inboxUnreadConvoMembers.length, 175 + profiles: inboxUnreadConvoMembers.slice(0, 3), 176 176 }, 177 177 ] 178 178 : []), ··· 182 182 ] satisfies ListItem[] 183 183 } 184 184 return [] 185 - }, [data, leftConvos, inboxPreviewConvos]) 185 + }, [data, leftConvos, hasInboxConvos, inboxUnreadConvoMembers]) 186 186 187 187 const onRefresh = useCallback(async () => { 188 188 setIsPTRing(true) ··· 231 231 232 232 // NOTE(APiligrim) 233 233 // Show empty state only if there are no conversations at all 234 - const actualConversations = conversations.filter( 234 + const activeConversations = conversations.filter( 235 235 item => item.type === 'CONVERSATION', 236 236 ) 237 - const hasInboxRequests = inboxPreviewConvos?.length > 0 238 237 239 - if (actualConversations.length === 0) { 238 + if (activeConversations.length === 0) { 240 239 return ( 241 240 <Layout.Screen> 242 241 <Header newChatControl={newChatControl} /> 243 242 <Layout.Center> 244 - {hasInboxRequests && ( 245 - <InboxPreview 246 - count={inboxPreviewConvos.length} 247 - profiles={inboxPreviewConvos} 248 - /> 243 + {!isLoading && hasInboxConvos && ( 244 + <InboxPreview profiles={inboxUnreadConvoMembers} /> 249 245 )} 250 246 {isLoading ? ( 251 247 <ChatListLoadingPlaceholder />
+2 -4
src/screens/Messages/components/InboxPreview.tsx
··· 1 1 import {View} from 'react-native' 2 - import {ChatBskyActorDefs} from '@atproto/api' 2 + import {type ChatBskyActorDefs} from '@atproto/api' 3 3 import {msg, Trans} from '@lingui/macro' 4 4 import {useLingui} from '@lingui/react' 5 5 ··· 12 12 13 13 export function InboxPreview({ 14 14 profiles, 15 - }: // count, 16 - { 15 + }: { 17 16 profiles: ChatBskyActorDefs.ProfileViewBasic[] 18 - count: number 19 17 }) { 20 18 const {_} = useLingui() 21 19 const t = useTheme()