Eliminate unknown groups and contacts from search results

This commit is contained in:
Scott Nonnenberg 2022-09-26 13:18:11 -07:00 committed by GitHub
parent a921f267f5
commit 5ed5483dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 11 deletions

View File

@ -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 {

View File

@ -185,6 +185,7 @@ export type ConversationType = {
// This is used by the CompositionInput for @mentions
sortedGroupMembers?: Array<ConversationType>;
title: string;
titleNoDefault?: string;
searchableTitle?: string;
unreadCount?: number;
isSelected?: boolean;

View File

@ -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)
)
);

View File

@ -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,

View File

@ -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'),

View File

@ -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;