enable search by username in message view #928

pull/930/head
Audric Ackermann 6 years ago
parent 55c1410793
commit 06aeb126c2
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -75,6 +75,10 @@ export class SearchResults extends React.Component<Props> {
))} ))}
</div> </div>
) : null} ) : null}
{haveFriends
? this.renderContacts(i18n('friendsHeader'), friends, true)
: null}
{haveMessages ? ( {haveMessages ? (
<div className="module-search-results__messages"> <div className="module-search-results__messages">
{hideMessagesHeader ? null : ( {hideMessagesHeader ? null : (
@ -95,4 +99,26 @@ export class SearchResults extends React.Component<Props> {
</div> </div>
); );
} }
private renderContacts(
header: string,
items: Array<ConversationListItemPropsType>,
friends?: boolean
) {
const { i18n, openConversation } = this.props;
return (
<div className="module-search-results__contacts">
<div className="module-search-results__contacts-header">{header}</div>
{items.map(contact => (
<ConversationListItem
key={contact.phoneNumber}
isFriend={friends}
{...contact}
onClick={openConversation}
i18n={i18n}
/>
))}
</div>
);
}
} }

@ -132,11 +132,16 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
public renderList(): JSX.Element | Array<JSX.Element | null> { public renderList(): JSX.Element | Array<JSX.Element | null> {
const { openConversationInternal, searchResults } = this.props; const { openConversationInternal, searchResults } = this.props;
const friends =
(searchResults &&
searchResults.contacts.filter(contact => contact.isFriend)) ||
[];
if (searchResults) { if (searchResults) {
return ( return (
<SearchResults <SearchResults
{...searchResults} {...searchResults}
friends={friends}
openConversation={openConversationInternal} openConversation={openConversationInternal}
i18n={window.i18n} i18n={window.i18n}
/> />

@ -172,7 +172,7 @@ async function queryConversationsAndContacts(
providedQuery: string, providedQuery: string,
options: SearchOptions options: SearchOptions
) { ) {
const { ourNumber, noteToSelf, isSecondaryDevice } = options; const { ourNumber, isSecondaryDevice } = options;
const query = providedQuery.replace(/[+-.()]*/g, ''); const query = providedQuery.replace(/[+-.()]*/g, '');
const searchResults: Array<ConversationType> = await searchConversations( const searchResults: Array<ConversationType> = await searchConversations(
@ -193,8 +193,8 @@ async function queryConversationsAndContacts(
); );
// Split into two groups - active conversations and items just from address book // Split into two groups - active conversations and items just from address book
let conversations: Array<string> = []; const conversations: Array<string> = [];
let contacts: Array<string> = []; const contacts: Array<string> = [];
const max = searchResults.length; const max = searchResults.length;
for (let i = 0; i < max; i += 1) { for (let i = 0; i < max; i += 1) {
const conversation = searchResults[i]; const conversation = searchResults[i];
@ -215,15 +215,6 @@ async function queryConversationsAndContacts(
} }
} }
// Inject synthetic Note to Self entry if query matches localized 'Note to Self'
if (noteToSelf.indexOf(providedQuery.toLowerCase()) !== -1) {
// ensure that we don't have duplicates in our results
contacts = contacts.filter(id => id !== ourNumber);
conversations = conversations.filter(id => id !== ourNumber);
contacts.unshift(ourNumber);
}
return { conversations, contacts }; return { conversations, contacts };
} }

Loading…
Cancel
Save