diff --git a/ts/components/leftpane/overlay/choose-action/ContactsListWithBreaks.tsx b/ts/components/leftpane/overlay/choose-action/ContactsListWithBreaks.tsx index ab14f2bf4..f4c400aaa 100644 --- a/ts/components/leftpane/overlay/choose-action/ContactsListWithBreaks.tsx +++ b/ts/components/leftpane/overlay/choose-action/ContactsListWithBreaks.tsx @@ -6,12 +6,13 @@ import styled, { CSSProperties } from 'styled-components'; import { DirectContactsByNameType, getDirectContactsByName, - getDirectContactsCount, + getContactsCount, } from '../../../../state/selectors/conversations'; import { leftPaneListWidth } from '../../LeftPane'; import { StyledLeftPaneList } from '../../LeftPaneList'; import { StyledChooseActionTitle } from './ActionRow'; import { ContactRow, ContactRowBreak } from './ContactRow'; +import { UserUtils } from '../../../../session/utils'; const StyledContactSection = styled.div` display: flex; @@ -90,6 +91,11 @@ const ContactListItemSection = () => { directContactsByNameWithBreaks.push(m); }); + directContactsByNameWithBreaks.unshift({ + id: UserUtils.getOurPubKeyStrFromCache(), + displayName: window.i18n('noteToSelf'), + }); + const length = Number(directContactsByNameWithBreaks.length); return ( @@ -118,7 +124,7 @@ const ContactListItemSection = () => { }; export const ContactsListWithBreaks = () => { - const contactsCount = useSelector(getDirectContactsCount); + const contactsCount = useSelector(getContactsCount); return ( diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 3efe592f6..86999952e 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -297,18 +297,12 @@ const _getLeftPaneConversationIds = ( .map(m => m.id); }; -const _getPrivateFriendsConversations = ( +const _getContacts = ( sortedConversations: Array ): Array => { return sortedConversations.filter(convo => { - return ( - convo.isPrivate && - !convo.isMe && - !convo.isBlocked && - convo.isApproved && - convo.didApproveMe && - convo.activeAt !== undefined - ); + // a private conversation not approved is a message request. Include them in the list of contacts + return !convo.isBlocked && convo.isPrivate && !convo.isMe; }); }; @@ -437,7 +431,6 @@ export const getUnreadConversationRequests = createSelector( * - approved (or message requests are disabled) * - active_at is set to something truthy */ - export const getLeftPaneConversationIds = createSelector( getSortedConversations, _getLeftPaneConversationIds @@ -450,10 +443,16 @@ export const getLeftPaneConversationIdsCount = createSelector( } ); -const getDirectContacts = createSelector(getSortedConversations, _getPrivateFriendsConversations); +/** + * Returns all the conversation ids of contacts which are + * - private + * - not me + * - not blocked + */ +const getContacts = createSelector(getSortedConversations, _getContacts); -export const getDirectContactsCount = createSelector( - getDirectContacts, +export const getContactsCount = createSelector( + getContacts, (contacts: Array) => contacts.length ); @@ -464,7 +463,7 @@ export type DirectContactsByNameType = { // make sure that createSelector is called here so this function is memoized export const getDirectContactsByName = createSelector( - getDirectContacts, + getContacts, (contacts: Array): Array => { const us = UserUtils.getOurPubKeyStrFromCache(); const extractedContacts = contacts @@ -475,10 +474,12 @@ export const getDirectContactsByName = createSelector( displayName: m.nickname || m.displayNameInProfile, }; }); + const extractedContactsNoDisplayName = sortBy( extractedContacts.filter(m => !m.displayName), 'id' ); + const extractedContactsWithDisplayName = sortBy( extractedContacts.filter(m => Boolean(m.displayName)), m => m.displayName?.toLowerCase()