fail quietly when search messagelookup gets dropped
This commit is contained in:
parent
7c5e6166ab
commit
aacf37b6d8
3 changed files with 24 additions and 1 deletions
|
@ -95,6 +95,7 @@ export const MessageSearchResult: FunctionComponent<PropsType> = React.memo(
|
|||
}, [showConversation, conversationId, id]);
|
||||
|
||||
if (!from || !to) {
|
||||
// Note: mapStateToProps() may return null if the message is not found.
|
||||
return <div />;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import {
|
|||
TARGETED_CONVERSATION_CHANGED,
|
||||
} from './conversations';
|
||||
import { removeDiacritics } from '../../util/removeDiacritics';
|
||||
import * as log from '../../logging/log';
|
||||
|
||||
const {
|
||||
searchMessages: dataSearchMessages,
|
||||
|
@ -344,6 +345,7 @@ export function reducer(
|
|||
action: Readonly<SearchActionType>
|
||||
): SearchStateType {
|
||||
if (action.type === 'SHOW_ARCHIVED_CONVERSATIONS') {
|
||||
log.info('search: show archived conversations, clearing message lookup');
|
||||
return getEmptyState();
|
||||
}
|
||||
|
||||
|
@ -357,6 +359,8 @@ export function reducer(
|
|||
}
|
||||
|
||||
if (action.type === 'SEARCH_CLEAR') {
|
||||
log.info('search: cleared, clearing message lookup');
|
||||
|
||||
return {
|
||||
...getEmptyState(),
|
||||
startSearchCounter: state.startSearchCounter,
|
||||
|
@ -397,6 +401,8 @@ export function reducer(
|
|||
};
|
||||
}
|
||||
|
||||
log.info('search: searching in new conversation, clearing message lookup');
|
||||
|
||||
return {
|
||||
...getEmptyState(),
|
||||
searchConversationId,
|
||||
|
@ -406,6 +412,8 @@ export function reducer(
|
|||
if (action.type === 'CLEAR_CONVERSATION_SEARCH') {
|
||||
const { searchConversationId } = state;
|
||||
|
||||
log.info('search: cleared conversation search, clearing message lookup');
|
||||
|
||||
return {
|
||||
...getEmptyState(),
|
||||
searchConversationId,
|
||||
|
@ -418,9 +426,12 @@ export function reducer(
|
|||
|
||||
// Reject if the associated query is not the most recent user-provided query
|
||||
if (state.query !== query) {
|
||||
log.info('search: query mismatch, ignoring message results');
|
||||
return state;
|
||||
}
|
||||
|
||||
log.info('search: got new messages, updating message lookup');
|
||||
|
||||
const messageIds = messages.map(message => message.id);
|
||||
|
||||
return {
|
||||
|
@ -438,6 +449,7 @@ export function reducer(
|
|||
|
||||
// Reject if the associated query is not the most recent user-provided query
|
||||
if (state.query !== query) {
|
||||
log.info('search: query mismatch, ignoring message results');
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -459,6 +471,9 @@ export function reducer(
|
|||
const { searchConversationId } = state;
|
||||
|
||||
if (searchConversationId && searchConversationId !== conversationId) {
|
||||
log.info(
|
||||
'search: targeted conversation changed, clearing message lookup'
|
||||
);
|
||||
return getEmptyState();
|
||||
}
|
||||
|
||||
|
@ -474,6 +489,9 @@ export function reducer(
|
|||
const { searchConversationId } = state;
|
||||
|
||||
if (searchConversationId && searchConversationId === conversationId) {
|
||||
log.info(
|
||||
'search: searched conversation unloaded, clearing message lookup'
|
||||
);
|
||||
return getEmptyState();
|
||||
}
|
||||
|
||||
|
@ -489,6 +507,8 @@ export function reducer(
|
|||
const { payload } = action;
|
||||
const { id } = payload;
|
||||
|
||||
log.info('search: message deleted, removing from message lookup');
|
||||
|
||||
return {
|
||||
...state,
|
||||
messageIds: reject(messageIds, messageId => id === messageId),
|
||||
|
|
|
@ -11,6 +11,7 @@ import { MessageSearchResult } from '../../components/conversationList/MessageSe
|
|||
import { getPreferredBadgeSelector } from '../selectors/badges';
|
||||
import { getIntl, getTheme } from '../selectors/user';
|
||||
import { getMessageSearchResultSelector } from '../selectors/search';
|
||||
import * as log from '../../logging/log';
|
||||
|
||||
type SmartProps = {
|
||||
id: string;
|
||||
|
@ -22,7 +23,8 @@ function mapStateToProps(state: StateType, ourProps: SmartProps) {
|
|||
|
||||
const props = getMessageSearchResultSelector(state)(id);
|
||||
if (!props) {
|
||||
throw new Error('SmartMessageSearchResult: no message was found');
|
||||
log.error('SmartMessageSearchResult: no message was found');
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue