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