enable search by username in message view #928

This commit is contained in:
Audric Ackermann 2020-02-26 17:18:41 +11:00
parent 55c1410793
commit 06aeb126c2
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
3 changed files with 34 additions and 12 deletions

View file

@ -75,6 +75,10 @@ export class SearchResults extends React.Component<Props> {
))}
</div>
) : null}
{haveFriends
? this.renderContacts(i18n('friendsHeader'), friends, true)
: null}
{haveMessages ? (
<div className="module-search-results__messages">
{hideMessagesHeader ? null : (
@ -95,4 +99,26 @@ export class SearchResults extends React.Component<Props> {
</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>
);
}
}

View file

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

View file

@ -172,7 +172,7 @@ async function queryConversationsAndContacts(
providedQuery: string,
options: SearchOptions
) {
const { ourNumber, noteToSelf, isSecondaryDevice } = options;
const { ourNumber, isSecondaryDevice } = options;
const query = providedQuery.replace(/[+-.()]*/g, '');
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
let conversations: Array<string> = [];
let contacts: Array<string> = [];
const conversations: Array<string> = [];
const contacts: Array<string> = [];
const max = searchResults.length;
for (let i = 0; i < max; i += 1) {
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 };
}