Skip to content

Commit

Permalink
Move deleted conversations to the bottom of the list (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis authored Oct 27, 2023
1 parent 62a6836 commit 932fde0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
17 changes: 10 additions & 7 deletions components/inbox-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
17 changes: 17 additions & 0 deletions util/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -47,6 +63,7 @@ const withTimeout = <T,>(ms: number, promise: Promise<T>): Promise<T | 'timeout'
};

export {
compareArrays,
delay,
deleteFromArray,
friendlyTimestamp,
Expand Down

0 comments on commit 932fde0

Please sign in to comment.