From 932fde02f19fcbda8bc6e6d5f2bd3c0537d9b3bc Mon Sep 17 00:00:00 2001 From: duogenesis <136373989+duogenesis@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:05:40 +1100 Subject: [PATCH] Move deleted conversations to the bottom of the list (#108) --- components/inbox-tab.tsx | 17 ++++++++++------- util/util.tsx | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/components/inbox-tab.tsx b/components/inbox-tab.tsx index ed7c4840..5acbaa18 100644 --- a/components/inbox-tab.tsx +++ b/components/inbox-tab.tsx @@ -23,6 +23,7 @@ import { OptionScreen } from './option-screen'; import { hideMeFromStrangersOptionGroup } from '../data/option-groups'; import { DefaultFlatList } from './default-flat-list'; import { Inbox, Conversation, observeInbox } from '../xmpp/xmpp'; +import { compareArrays } from '../util/util'; // TODO: Blocking people should remove them from each others' inboxes @@ -114,14 +115,16 @@ const InboxTab_ = ({navigation}) => { const pageSize = 10; const page = [...section.conversations] .sort((a, b) => { - if ( - sectionName === 'intros' && - sortByIndex === 1 && - a.matchPercentage !== b.matchPercentage - ) { - return b.matchPercentage - a.matchPercentage + if (sectionName === 'intros' && sortByIndex === 1) { + return compareArrays( + [!b.isDeletedUser, b.matchPercentage, +b.lastMessageTimestamp], + [!a.isDeletedUser, a.matchPercentage, +a.lastMessageTimestamp], + ); } else { - return +b.lastMessageTimestamp - +a.lastMessageTimestamp + return compareArrays( + [!b.isDeletedUser, +b.lastMessageTimestamp, b.matchPercentage], + [!a.isDeletedUser, +a.lastMessageTimestamp, a.matchPercentage], + ); } }) .slice( diff --git a/util/util.tsx b/util/util.tsx index fef470ce..83a9665c 100644 --- a/util/util.tsx +++ b/util/util.tsx @@ -13,6 +13,22 @@ const isMobile = () => { ); }; +/* Compare arrays as they would be in Python + */ +const compareArrays = (arrA: any[], arrB: any[]): number => { + let minLength = Math.min(arrA.length, arrB.length); + + for (let i = 0; i < minLength; i++) { + if (arrA[i] < arrB[i]) { + return -1; + } else if (arrA[i] > arrB[i]) { + return 1; + } + } + + return arrA.length - arrB.length; +} + const friendlyTimestamp = (date: Date): string => { if (isToday(date)) { // Format as 'hh:mm' @@ -47,6 +63,7 @@ const withTimeout = (ms: number, promise: Promise): Promise