From fade51e9eba84cfba1a8797aafc4958ab3764deb Mon Sep 17 00:00:00 2001
From: hailey <me@haileyok.com>
Date: Wed, 30 Jul 2025 11:00:14 -0700
Subject: Rework variable naming, logic for rendering chat requests (#8737)

---
 src/screens/Messages/ChatList.tsx | 58 ++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 31 deletions(-)

(limited to 'src/screens/Messages/ChatList.tsx')

diff --git a/src/screens/Messages/ChatList.tsx b/src/screens/Messages/ChatList.tsx
index c37a025cc..345446464 100644
--- a/src/screens/Messages/ChatList.tsx
+++ b/src/screens/Messages/ChatList.tsx
@@ -55,7 +55,7 @@ type ListItem =
 function renderItem({item}: {item: ListItem}) {
   switch (item.type) {
     case 'INBOX':
-      return <InboxPreview count={item.count} profiles={item.profiles} />
+      return <InboxPreview profiles={item.profiles} />
     case 'CONVERSATION':
       return <ChatListItem convo={item.conversation} />
   }
@@ -140,22 +140,24 @@ export function MessagesScreenInner({navigation, route}: Props) {
 
   const leftConvos = useLeftConvos()
 
-  const inboxPreviewConvos = useMemo(() => {
-    const inbox =
-      inboxData?.pages
-        .flatMap(page => page.convos)
-        .filter(
-          convo =>
-            !leftConvos.includes(convo.id) &&
-            !convo.muted &&
-            convo.unreadCount > 0 &&
-            convo.members.every(member => member.handle !== 'missing.invalid'),
-        ) ?? []
-
-    return inbox
-      .map(x => x.members.find(y => y.did !== currentAccount?.did))
-      .filter(x => !!x)
-  }, [inboxData, leftConvos, currentAccount?.did])
+  const inboxAllConvos =
+    inboxData?.pages
+      .flatMap(page => page.convos)
+      .filter(
+        convo =>
+          !leftConvos.includes(convo.id) &&
+          !convo.muted &&
+          convo.members.every(member => member.handle !== 'missing.invalid'),
+      ) ?? []
+  const hasInboxConvos = inboxAllConvos?.length > 0
+
+  const inboxUnreadConvos = inboxAllConvos.filter(
+    convo => convo.unreadCount > 0,
+  )
+
+  const inboxUnreadConvoMembers = inboxUnreadConvos
+    .map(x => x.members.find(y => y.did !== currentAccount?.did))
+    .filter(x => !!x)
 
   const conversations = useMemo(() => {
     if (data?.pages) {
@@ -164,15 +166,13 @@ export function MessagesScreenInner({navigation, route}: Props) {
         // filter out convos that are actively being left
         .filter(convo => !leftConvos.includes(convo.id))
 
-      const hasInboxRequests = inboxPreviewConvos?.length > 0
-
       return [
-        ...(hasInboxRequests
+        ...(hasInboxConvos
           ? [
               {
                 type: 'INBOX' as const,
-                count: inboxPreviewConvos.length,
-                profiles: inboxPreviewConvos.slice(0, 3),
+                count: inboxUnreadConvoMembers.length,
+                profiles: inboxUnreadConvoMembers.slice(0, 3),
               },
             ]
           : []),
@@ -182,7 +182,7 @@ export function MessagesScreenInner({navigation, route}: Props) {
       ] satisfies ListItem[]
     }
     return []
-  }, [data, leftConvos, inboxPreviewConvos])
+  }, [data, leftConvos, hasInboxConvos, inboxUnreadConvoMembers])
 
   const onRefresh = useCallback(async () => {
     setIsPTRing(true)
@@ -231,21 +231,17 @@ export function MessagesScreenInner({navigation, route}: Props) {
 
   // NOTE(APiligrim)
   // Show empty state only if there are no conversations at all
-  const actualConversations = conversations.filter(
+  const activeConversations = conversations.filter(
     item => item.type === 'CONVERSATION',
   )
-  const hasInboxRequests = inboxPreviewConvos?.length > 0
 
-  if (actualConversations.length === 0) {
+  if (activeConversations.length === 0) {
     return (
       <Layout.Screen>
         <Header newChatControl={newChatControl} />
         <Layout.Center>
-          {hasInboxRequests && (
-            <InboxPreview
-              count={inboxPreviewConvos.length}
-              profiles={inboxPreviewConvos}
-            />
+          {!isLoading && hasInboxConvos && (
+            <InboxPreview profiles={inboxUnreadConvoMembers} />
           )}
           {isLoading ? (
             <ChatListLoadingPlaceholder />
-- 
cgit 1.4.1

