|
|
|
@ -76,58 +76,41 @@ export type SearchResultsMergedListItem =
|
|
|
|
|
|
|
|
|
|
export const getSearchResultsList = createSelector([getSearchResults], searchState => {
|
|
|
|
|
const { contactsAndGroups, messages } = searchState;
|
|
|
|
|
const builtList: Array<SearchResultsMergedListItem> = [];
|
|
|
|
|
const builtList = [];
|
|
|
|
|
|
|
|
|
|
if (contactsAndGroups.length) {
|
|
|
|
|
const us = UserUtils.getOurPubKeyStrFromCache();
|
|
|
|
|
let usIndex: number = -1;
|
|
|
|
|
|
|
|
|
|
const idsWithNameAndType = contactsAndGroups.map(m => ({
|
|
|
|
|
const contactsWithNameAndType = contactsAndGroups.map(m => ({
|
|
|
|
|
contactConvoId: m.id,
|
|
|
|
|
displayName: m.nickname || m.displayNameInProfile,
|
|
|
|
|
type: m.type,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const groupsAndCommunities = sortBy(
|
|
|
|
|
remove(idsWithNameAndType, m => m.type === ConversationTypeEnum.GROUP),
|
|
|
|
|
remove(contactsWithNameAndType, m => m.type === ConversationTypeEnum.GROUP),
|
|
|
|
|
m => m.displayName?.toLowerCase()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const idsWithNoDisplayNamesOrStartingWithANumber = sortBy(
|
|
|
|
|
remove(idsWithNameAndType, m => !m.displayName || m.displayName[0].match(/^[0-9]+$/)),
|
|
|
|
|
m => m.contactConvoId
|
|
|
|
|
const contactsStartingWithANumber = sortBy(
|
|
|
|
|
remove(
|
|
|
|
|
contactsWithNameAndType,
|
|
|
|
|
m => !m.displayName || (m.displayName && m.displayName[0].match(/^[0-9]+$/))
|
|
|
|
|
),
|
|
|
|
|
m => m.displayName || m.contactConvoId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// add a break wherever needed
|
|
|
|
|
// let currentChar = '';
|
|
|
|
|
for (let i = 0; i < idsWithNameAndType.length; i++) {
|
|
|
|
|
const m = idsWithNameAndType[i];
|
|
|
|
|
if (m.contactConvoId === us) {
|
|
|
|
|
usIndex = i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// we might want breaks again in future
|
|
|
|
|
// if (
|
|
|
|
|
// idsWithNameAndType.length > 1 &&
|
|
|
|
|
// m.displayName &&
|
|
|
|
|
// m.displayName[0].toLowerCase() !== currentChar
|
|
|
|
|
// ) {
|
|
|
|
|
// currentChar = m.displayName[0].toLowerCase();
|
|
|
|
|
// builtList.push(currentChar.toUpperCase());
|
|
|
|
|
// }
|
|
|
|
|
builtList.push(m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builtList.unshift(...groupsAndCommunities);
|
|
|
|
|
builtList.push(
|
|
|
|
|
...groupsAndCommunities,
|
|
|
|
|
...contactsWithNameAndType,
|
|
|
|
|
...contactsStartingWithANumber
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (idsWithNoDisplayNamesOrStartingWithANumber.length) {
|
|
|
|
|
// builtList.push('#');
|
|
|
|
|
builtList.push(...idsWithNoDisplayNamesOrStartingWithANumber);
|
|
|
|
|
}
|
|
|
|
|
const us = UserUtils.getOurPubKeyStrFromCache();
|
|
|
|
|
const hasUs = remove(builtList, m => m.contactConvoId === us);
|
|
|
|
|
|
|
|
|
|
if (usIndex !== -1) {
|
|
|
|
|
if (hasUs.length) {
|
|
|
|
|
builtList.unshift({ contactConvoId: us, displayName: window.i18n('noteToSelf') });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builtList.unshift(window.i18n('sessionConversations'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|