Skip to content

Commit

Permalink
Fix bug in inbox/archive stats
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Nov 4, 2023
1 parent d098d3d commit 58b6649
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
8 changes: 4 additions & 4 deletions components/inbox-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const InboxTab_ = ({navigation}) => {
}

return showArchive ?
_inboxStats.chats.numUnreadUnavailable :
_inboxStats.chats.numUnreadAvailable;
_inboxStats.chats.numUnreadArchive :
_inboxStats.chats.numUnreadInbox;
})();

const numUnreadIntros = (() => {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion components/tab-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TabBar = ({state, descriptors, navigation}) => {
return;
}

const numUnreadAvailable = inboxStats(inbox).numUnreadAvailable;
const numUnreadAvailable = inboxStats(inbox).numUnreadInbox;

setInboxHasUnread(numUnreadAvailable > 0);
}, []);
Expand Down
55 changes: 29 additions & 26 deletions xmpp/xmpp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

Expand Down

0 comments on commit 58b6649

Please sign in to comment.