Skip to content

Commit e39c6e5

Browse files
Don't search conversations if searching within conversation
1 parent c9fd199 commit e39c6e5

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

app/sql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ async function searchConversations(query, { limit } = {}) {
17181718
name LIKE $name OR
17191719
profileName LIKE $profileName
17201720
)
1721-
ORDER BY id ASC
1721+
ORDER BY active_at DESC
17221722
LIMIT $limit`,
17231723
{
17241724
$id: `%${query}%`,

ts/components/MainHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class MainHeader extends React.Component<PropsType> {
7676
searchConversationId,
7777
} = this.props;
7878

79-
if (searchDiscussions) {
79+
if (searchDiscussions && !searchConversationId) {
8080
searchDiscussions(searchTerm, {
8181
noteToSelf: i18n('noteToSelf').toLowerCase(),
8282
ourNumber,
@@ -89,7 +89,7 @@ export class MainHeader extends React.Component<PropsType> {
8989
regionCode,
9090
});
9191
}
92-
}, 50);
92+
}, 200);
9393

9494
public updateSearch = (event: React.FormEvent<HTMLInputElement>) => {
9595
const {

ts/state/ducks/search.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ type SearchDiscussionsResultsKickoffActionType = {
6767
payload: Promise<SearchDiscussionsResultsPayloadType>;
6868
};
6969

70-
type SearchMessagesResultsPendingActionType = {
71-
type: 'SEARCH_MESSAGES_RESULTS_PENDING';
72-
payload: SearchMessagesResultsPayloadType;
73-
};
74-
type SearchDiscussionsResultsPendingActionType = {
75-
type: 'SEARCH_DISCUSSIONS_RESULTS_PENDING';
76-
payload: SearchDiscussionsResultsPayloadType;
77-
};
7870
type SearchMessagesResultsFulfilledActionType = {
7971
type: 'SEARCH_MESSAGES_RESULTS_FULFILLED';
8072
payload: SearchMessagesResultsPayloadType;
@@ -108,8 +100,6 @@ type SearchInConversationActionType = {
108100
export type SEARCH_TYPES =
109101
| SearchMessagesResultsKickoffActionType
110102
| SearchDiscussionsResultsKickoffActionType
111-
| SearchMessagesResultsPendingActionType
112-
| SearchDiscussionsResultsPendingActionType
113103
| SearchMessagesResultsFulfilledActionType
114104
| SearchDiscussionsResultsFulfilledActionType
115105
| UpdateSearchTermActionType
@@ -327,9 +317,22 @@ export function reducer(
327317
const { payload } = action;
328318
const { query } = payload;
329319

320+
const hasQuery = Boolean(query && query.length >= 2);
321+
const isWithinConversation = Boolean(state.searchConversationId);
322+
330323
return {
331324
...state,
332325
query,
326+
messagesLoading: hasQuery,
327+
...(hasQuery
328+
? {
329+
messageIds: [],
330+
messageLookup: {},
331+
discussionsLoading: !isWithinConversation,
332+
contacts: [],
333+
conversations: [],
334+
}
335+
: {}),
333336
};
334337
}
335338

@@ -357,24 +360,6 @@ export function reducer(
357360
};
358361
}
359362

360-
if (action.type === 'SEARCH_MESSAGES_RESULTS_PENDING') {
361-
return {
362-
...state,
363-
messageIds: [],
364-
messageLookup: {},
365-
messagesLoading: true,
366-
};
367-
}
368-
369-
if (action.type === 'SEARCH_DISCUSSIONS_RESULTS_PENDING') {
370-
return {
371-
...state,
372-
contacts: [],
373-
conversations: [],
374-
discussionsLoading: true,
375-
};
376-
}
377-
378363
if (action.type === 'SEARCH_MESSAGES_RESULTS_FULFILLED') {
379364
const { payload } = action;
380365
const { messages, normalizedPhoneNumber, query } = payload;

0 commit comments

Comments
 (0)