From 1e6e8c3be40576955fc3e718dcee79bb7b2a9baa Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 19 Jul 2023 00:59:21 +0200 Subject: [PATCH] Add !unread: internal filter --- ts/util/filterAndSortConversations.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ts/util/filterAndSortConversations.ts b/ts/util/filterAndSortConversations.ts index 01a4cfc03..ed50f08c5 100644 --- a/ts/util/filterAndSortConversations.ts +++ b/ts/util/filterAndSortConversations.ts @@ -7,6 +7,7 @@ import type { ConversationType } from '../state/ducks/conversations'; import { parseAndFormatPhoneNumber } from './libphonenumberInstance'; import { WEEK } from './durations'; import { fuseGetFnRemoveDiacritics, getCachedFuseIndex } from './fuse'; +import { getConversationUnreadCountForAppBadge } from './getConversationUnreadCountForAppBadge'; // Fuse.js scores have order of 0.01 const ACTIVE_AT_SCORE_FACTOR = (1 / WEEK) * 0.01; @@ -71,6 +72,23 @@ COMMANDS.set('groupIdEndsWith', (conversations, query) => { return conversations.filter(convo => convo.groupId?.endsWith(query)); }); +COMMANDS.set('unread', conversations => { + const canCountMutedConversations = + window.storage.get('badge-count-muted-conversations') || false; + + return conversations.filter(convo => { + return getConversationUnreadCountForAppBadge( + { + ...convo, + + // Difference between redux type and conversation attributes + active_at: convo.activeAt, + }, + canCountMutedConversations + ); + }); +}); + // See https://fusejs.io/examples.html#extended-search for // extended search documentation. function searchConversations(