diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index babf1ec04..68f7d02e1 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -1912,6 +1912,7 @@ export class ConversationModel extends window.Backbone sortedGroupMembers, timestamp, title: this.getTitle(), + titleNoDefault: this.getTitleNoDefault(), typingContactId: typingMostRecent?.senderId, searchableTitle: isMe(this.attributes) ? window.i18n('noteToSelf') @@ -4950,7 +4951,21 @@ export class ConversationModel extends window.Backbone }); } - getTitle({ isShort = false }: { isShort?: boolean } = {}): string { + getTitle(options?: { isShort?: boolean }): string { + const title = this.getTitleNoDefault(options); + if (title) { + return title; + } + + if (isDirectConversation(this.attributes)) { + return window.i18n('unknownContact'); + } + return window.i18n('unknownGroup'); + } + + getTitleNoDefault({ isShort = false }: { isShort?: boolean } = {}): + | string + | undefined { if (isDirectConversation(this.attributes)) { const username = this.get('username'); @@ -4959,11 +4974,10 @@ export class ConversationModel extends window.Backbone (isShort ? this.get('profileName') : undefined) || this.getProfileName() || this.getNumber() || - (username && window.i18n('at-username', { username })) || - window.i18n('unknownContact') + (username && window.i18n('at-username', { username })) ); } - return this.get('name') || window.i18n('unknownGroup'); + return this.get('name'); } getProfileName(): string | undefined { diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index b43c8d915..d2ed3a094 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -185,6 +185,7 @@ export type ConversationType = { // This is used by the CompositionInput for @mentions sortedGroupMembers?: Array; title: string; + titleNoDefault?: string; searchableTitle?: string; unreadCount?: number; isSelected?: boolean; diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index b38826867..7ee590ce3 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -472,7 +472,7 @@ export const getAllComposableConversations = createSelector( !isConversationUnregistered(conversation) && // All conversation should have a title except in weird cases where // they don't, in that case we don't want to show these for Forwarding. - conversation.title && + conversation.titleNoDefault && hasDisplayInfo(conversation) ) ); diff --git a/ts/test-both/helpers/getDefaultConversation.ts b/ts/test-both/helpers/getDefaultConversation.ts index 7f3c9c66d..a0ebe192f 100644 --- a/ts/test-both/helpers/getDefaultConversation.ts +++ b/ts/test-both/helpers/getDefaultConversation.ts @@ -36,6 +36,7 @@ export function getDefaultConversation( markedUnread: Boolean(overrideProps.markedUnread), sharedGroupNames: [], title: `${firstName} ${lastName}`, + titleNoDefault: `${firstName} ${lastName}`, type: 'direct' as const, uuid: UUID.generate().toString(), ...overrideProps, diff --git a/ts/test-both/state/selectors/conversations_test.ts b/ts/test-both/state/selectors/conversations_test.ts index 9476d8bb1..d6d68e6c7 100644 --- a/ts/test-both/state/selectors/conversations_test.ts +++ b/ts/test-both/state/selectors/conversations_test.ts @@ -65,21 +65,26 @@ describe('both/state/selectors/conversations', () => { }; function makeConversation(id: string): ConversationType { + const title = `${id} title`; return getDefaultConversation({ id, - searchableTitle: `${id} title`, - title: `${id} title`, + searchableTitle: title, + title, + titleNoDefault: title, }); } function makeConversationWithUuid( id: string ): ConversationType & { uuid: UUIDStringType } { + const title = `${id} title`; + return getDefaultConversationWithUuid( { id, - searchableTitle: `${id} title`, - title: `${id} title`, + searchableTitle: title, + title, + titleNoDefault: title, }, UUID.fromPrefix(id).toString() ); @@ -555,7 +560,8 @@ describe('both/state/selectors/conversations', () => { ...makeConversation('convo-6'), profileSharing: true, name: 'Should Be Dropped (no title)', - title: null, + title: 'Unknown group', + titleNoDefault: undefined, }, 'convo-7': { ...makeConversation('convo-7'), diff --git a/ts/util/filterAndSortConversations.ts b/ts/util/filterAndSortConversations.ts index 7b68765c6..0202808a9 100644 --- a/ts/util/filterAndSortConversations.ts +++ b/ts/util/filterAndSortConversations.ts @@ -118,7 +118,9 @@ export function filterAndSortConversationsByRecent( if (searchTerm.length) { const now = Date.now(); - return searchConversations(conversations, searchTerm, regionCode) + const withoutUnknown = conversations.filter(item => item.titleNoDefault); + + return searchConversations(withoutUnknown, searchTerm, regionCode) .slice() .sort((a, b) => { const { activeAt: aActiveAt = 0, left: aLeft = false } = a.item;