From 58b6649dbb952d114b5040ba37a6352a4bfb52b4 Mon Sep 17 00:00:00 2001 From: duogenesis <136373989+duogenesis@users.noreply.github.com> Date: Sat, 4 Nov 2023 14:04:22 +1100 Subject: [PATCH] Fix bug in inbox/archive stats --- components/inbox-tab.tsx | 8 +++--- components/tab-bar.tsx | 2 +- xmpp/xmpp.tsx | 55 +++++++++++++++++++++------------------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/components/inbox-tab.tsx b/components/inbox-tab.tsx index fde2a5a5..979e5bad 100644 --- a/components/inbox-tab.tsx +++ b/components/inbox-tab.tsx @@ -62,8 +62,8 @@ const InboxTab_ = ({navigation}) => { } return showArchive ? - _inboxStats.chats.numUnreadUnavailable : - _inboxStats.chats.numUnreadAvailable; + _inboxStats.chats.numUnreadArchive : + _inboxStats.chats.numUnreadInbox; })(); const numUnreadIntros = (() => { @@ -72,8 +72,8 @@ const InboxTab_ = ({navigation}) => { } return showArchive ? - _inboxStats.intros.numUnreadUnavailable : - _inboxStats.intros.numUnreadAvailable; + _inboxStats.intros.numUnreadArchive : + _inboxStats.intros.numUnreadInbox; })(); const buttonOpacity = useRef(new Animated.Value(0)).current; diff --git a/components/tab-bar.tsx b/components/tab-bar.tsx index dee07eb9..43b90643 100644 --- a/components/tab-bar.tsx +++ b/components/tab-bar.tsx @@ -30,7 +30,7 @@ const TabBar = ({state, descriptors, navigation}) => { return; } - const numUnreadAvailable = inboxStats(inbox).numUnreadAvailable; + const numUnreadAvailable = inboxStats(inbox).numUnreadInbox; setInboxHasUnread(numUnreadAvailable > 0); }, []); diff --git a/xmpp/xmpp.tsx b/xmpp/xmpp.tsx index f556f7e7..304b50d1 100644 --- a/xmpp/xmpp.tsx +++ b/xmpp/xmpp.tsx @@ -61,57 +61,60 @@ type Inbox = { const inboxStats = (inbox: Inbox): { chats: { - numUnreadAvailable: number - numUnreadUnavailable: number + numUnreadInbox: number + numUnreadArchive: number } intros: { - numUnreadAvailable: number - numUnreadUnavailable: number + numUnreadInbox: number + numUnreadArchive: number } - numUnreadAvailable: number - numUnreadUnavailable: number + numUnreadInbox: number + numUnreadArchive: number } => { - const unreadAvailable = (sum: number, c: Conversation) => - sum + ( c.isAvailableUser && !c.lastMessageRead ? 1 : 0); + const isArchived = (c: Conversation) => + !c.isAvailableUser || c.wasArchivedByMe; - const unreadUnavailable = (sum: number, c: Conversation) => - sum + (!c.isAvailableUser && !c.lastMessageRead ? 1 : 0); + const unreadInbox = (sum: number, c: Conversation) => + sum + (!isArchived(c) && !c.lastMessageRead ? 1 : 0); + + const unreadArchive = (sum: number, c: Conversation) => + sum + ( isArchived(c) && !c.lastMessageRead ? 1 : 0); const chats = { - numUnreadAvailable: inbox.chats.conversations.reduce( - unreadAvailable, + numUnreadInbox: inbox.chats.conversations.reduce( + unreadInbox, 0 ), - numUnreadUnavailable: inbox.chats.conversations.reduce( - unreadUnavailable, + numUnreadArchive: inbox.chats.conversations.reduce( + unreadArchive, 0 ), }; const intros = { - numUnreadAvailable: inbox.intros.conversations.reduce( - unreadAvailable, + numUnreadInbox: inbox.intros.conversations.reduce( + unreadInbox, 0 ), - numUnreadUnavailable: inbox.intros.conversations.reduce( - unreadUnavailable, + numUnreadArchive: inbox.intros.conversations.reduce( + unreadArchive, 0 ), }; - const numUnreadAvailable = ( - chats .numUnreadAvailable + - intros.numUnreadAvailable); + const numUnreadInbox = ( + chats .numUnreadInbox + + intros.numUnreadInbox); - const numUnreadUnavailable = ( - chats .numUnreadUnavailable + - intros.numUnreadUnavailable); + const numUnreadArchive = ( + chats .numUnreadArchive + + intros.numUnreadArchive); return { chats, intros, - numUnreadAvailable, - numUnreadUnavailable, + numUnreadInbox, + numUnreadArchive, }; };