remove search messages frpm search result

pull/1884/head
audric 4 years ago
parent ec2eab6e23
commit 38665e105a

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import { PropsForSearchResults } from '../state/ducks/conversations';
import { import {
ConversationListItemProps, ConversationListItemProps,
MemoConversationListItemWithDetails, MemoConversationListItemWithDetails,
@ -9,7 +8,6 @@ export type SearchResultsProps = {
contacts: Array<ConversationListItemProps>; contacts: Array<ConversationListItemProps>;
conversations: Array<ConversationListItemProps>; conversations: Array<ConversationListItemProps>;
hideMessagesHeader: boolean; hideMessagesHeader: boolean;
messages: Array<PropsForSearchResults>;
searchTerm: string; searchTerm: string;
}; };
@ -25,12 +23,11 @@ const ContactsItem = (props: { header: string; items: Array<ConversationListItem
}; };
export const SearchResults = (props: SearchResultsProps) => { export const SearchResults = (props: SearchResultsProps) => {
const { conversations, contacts, messages, searchTerm } = props; const { conversations, contacts, searchTerm } = props;
const haveConversations = conversations && conversations.length; const haveConversations = conversations && conversations.length;
const haveContacts = contacts && contacts.length; const haveContacts = contacts && contacts.length;
const haveMessages = messages && messages.length; const noResults = !haveConversations && !haveContacts;
const noResults = !haveConversations && !haveContacts && !haveMessages;
return ( return (
<div className="module-search-results"> <div className="module-search-results">

@ -1036,7 +1036,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
(m: any) => m.get('received_at') > newestUnreadDate (m: any) => m.get('received_at') > newestUnreadDate
); );
const ourNumber = UserUtils.getOurPubKeyStrFromCache(); const ourNumber = UserUtils.getOurPubKeyStrFromCache();
return !stillUnread.some(m => m.getPropsForMessage()?.text?.indexOf(`@${ourNumber}`) !== -1); return !stillUnread.some(m => m.get('body')?.indexOf(`@${ourNumber}`) !== -1);
})(); })();
if (mentionRead) { if (mentionRead) {

@ -37,7 +37,6 @@ import {
PropsForGroupUpdateName, PropsForGroupUpdateName,
PropsForGroupUpdateRemove, PropsForGroupUpdateRemove,
PropsForMessageWithoutConvoProps, PropsForMessageWithoutConvoProps,
PropsForSearchResults,
} from '../state/ducks/conversations'; } from '../state/ducks/conversations';
import { VisibleMessage } from '../session/messages/outgoing/visibleMessage/VisibleMessage'; import { VisibleMessage } from '../session/messages/outgoing/visibleMessage/VisibleMessage';
import { buildSyncMessage } from '../session/utils/syncUtils'; import { buildSyncMessage } from '../session/utils/syncUtils';
@ -88,7 +87,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
perfStart(`getPropsMessage-${this.id}`); perfStart(`getPropsMessage-${this.id}`);
const messageProps: MessageModelPropsWithoutConvoProps = { const messageProps: MessageModelPropsWithoutConvoProps = {
propsForMessage: this.getPropsForMessage(), propsForMessage: this.getPropsForMessage(),
propsForSearchResult: this.getPropsForSearchResult(),
propsForDataExtractionNotification: this.getPropsForDataExtractionNotification(), propsForDataExtractionNotification: this.getPropsForDataExtractionNotification(),
propsForGroupInvitation: this.getPropsForGroupInvitation(), propsForGroupInvitation: this.getPropsForGroupInvitation(),
propsForGroupNotification: this.getPropsForGroupNotification(), propsForGroupNotification: this.getPropsForGroupNotification(),
@ -497,25 +495,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return 'sending'; return 'sending';
} }
public getPropsForSearchResult(): PropsForSearchResults {
const fromNumber = this.getSource();
const from = this.findAndFormatContact(fromNumber);
const toNumber = this.get('conversationId');
const to = this.findAndFormatContact(toNumber);
return {
from,
to,
// isSelected: this.isSelected,
id: this.id as string,
conversationId: this.get('conversationId'),
source: this.get('source'),
receivedAt: this.get('received_at'),
snippet: this.get('snippet'),
};
}
public getPropsForMessage(options: any = {}): PropsForMessageWithoutConvoProps { public getPropsForMessage(options: any = {}): PropsForMessageWithoutConvoProps {
const sender = this.getSource(); const sender = this.getSource();
const expirationLength = this.get('expireTimer') * 1000; const expirationLength = this.get('expireTimer') * 1000;

@ -19,7 +19,6 @@ import { omit } from 'lodash';
export type MessageModelPropsWithoutConvoProps = { export type MessageModelPropsWithoutConvoProps = {
propsForMessage: PropsForMessageWithoutConvoProps; propsForMessage: PropsForMessageWithoutConvoProps;
propsForSearchResult: PropsForSearchResults | null;
propsForGroupInvitation: PropsForGroupInvitation | null; propsForGroupInvitation: PropsForGroupInvitation | null;
propsForTimerNotification: PropsForExpirationTimer | null; propsForTimerNotification: PropsForExpirationTimer | null;
propsForDataExtractionNotification: PropsForDataExtractionNotification | null; propsForDataExtractionNotification: PropsForDataExtractionNotification | null;
@ -128,16 +127,6 @@ export type PropsForGroupInvitation = {
isUnread: boolean; isUnread: boolean;
}; };
export type PropsForSearchResults = {
from: FindAndFormatContactType;
to: FindAndFormatContactType;
id: string;
conversationId: string;
source: string;
receivedAt: number | undefined;
snippet?: string; //not sure about the type of snippet
};
export type PropsForAttachment = { export type PropsForAttachment = {
id: number; id: number;
contentType: string; contentType: string;

@ -1,12 +1,9 @@
import { AdvancedSearchOptions, SearchOptions } from '../../types/Search'; import { AdvancedSearchOptions, SearchOptions } from '../../types/Search';
import { cleanSearchTerm } from '../../util/cleanSearchTerm'; import { cleanSearchTerm } from '../../util/cleanSearchTerm';
import { searchConversations, searchMessages } from '../../../ts/data/data'; import { searchConversations, searchMessages } from '../../../ts/data/data';
import { makeLookup } from '../../util/makeLookup';
import { PropsForSearchResults, ReduxConversationType } from './conversations'; import { ReduxConversationType } from './conversations';
import { PubKey } from '../../session/types'; import { PubKey } from '../../session/types';
import { MessageModel } from '../../models/message';
import { MessageModelType } from '../../models/messageType';
import { ConversationTypeEnum } from '../../models/conversation'; import { ConversationTypeEnum } from '../../models/conversation';
// State // State
@ -15,11 +12,7 @@ export type SearchStateType = {
query: string; query: string;
normalizedPhoneNumber?: string; normalizedPhoneNumber?: string;
// We need to store messages here, because they aren't anywhere else in state // We need to store messages here, because they aren't anywhere else in state
messages: Array<PropsForSearchResults>;
selectedMessage?: string; selectedMessage?: string;
messageLookup: {
[key: string]: PropsForSearchResults;
};
// For conversations we store just the id, and pull conversation props in the selector // For conversations we store just the id, and pull conversation props in the selector
conversations: Array<string>; conversations: Array<string>;
contacts: Array<string>; contacts: Array<string>;
@ -29,7 +22,6 @@ export type SearchStateType = {
type SearchResultsPayloadType = { type SearchResultsPayloadType = {
query: string; query: string;
normalizedPhoneNumber?: string; normalizedPhoneNumber?: string;
messages: Array<PropsForSearchResults>;
conversations: Array<string>; conversations: Array<string>;
contacts: Array<string>; contacts: Array<string>;
}; };
@ -102,7 +94,6 @@ async function doSearch(query: string, options: SearchOptions): Promise<SearchRe
normalizedPhoneNumber: PubKey.normalize(query), normalizedPhoneNumber: PubKey.normalize(query),
conversations, conversations,
contacts, contacts,
messages: getMessageProps(filteredMessages) || [],
}; };
} }
export function clearSearch(): ClearSearchActionType { export function clearSearch(): ClearSearchActionType {
@ -200,23 +191,6 @@ function getAdvancedSearchOptionsFromQuery(query: string): AdvancedSearchOptions
return filters; return filters;
} }
const getMessageProps = (messages: Array<PropsForSearchResults>) => {
if (!messages || !messages.length) {
return [];
}
return messages.map(message => {
const overridenProps = {
...message,
type: 'incoming' as MessageModelType,
};
const model = new MessageModel(overridenProps);
return model.getPropsForSearchResult();
});
};
async function queryMessages(query: string) { async function queryMessages(query: string) {
try { try {
const normalized = cleanSearchTerm(query); const normalized = cleanSearchTerm(query);
@ -271,8 +245,6 @@ async function queryConversationsAndContacts(providedQuery: string, options: Sea
export const initialSearchState: SearchStateType = { export const initialSearchState: SearchStateType = {
query: '', query: '',
messages: [],
messageLookup: {},
conversations: [], conversations: [],
contacts: [], contacts: [],
}; };
@ -302,13 +274,12 @@ export function reducer(state: SearchStateType | undefined, action: SEARCH_TYPES
if (action.type === 'SEARCH_RESULTS_FULFILLED') { if (action.type === 'SEARCH_RESULTS_FULFILLED') {
const { payload } = action; const { payload } = action;
const { query, messages, normalizedPhoneNumber, conversations, contacts } = payload; const { query, normalizedPhoneNumber, conversations, contacts } = payload;
// 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) {
return state; return state;
} }
const filteredMessage = messages.filter(message => message !== undefined);
return { return {
...state, ...state,
@ -316,8 +287,6 @@ export function reducer(state: SearchStateType | undefined, action: SEARCH_TYPES
normalizedPhoneNumber, normalizedPhoneNumber,
conversations, conversations,
contacts, contacts,
messages: filteredMessage,
messageLookup: makeLookup(filteredMessage, 'id'),
}; };
} }

@ -23,13 +23,8 @@ export const isSearching = createSelector(getSearch, (state: SearchStateType) =>
}); });
export const getSearchResults = createSelector( export const getSearchResults = createSelector(
[getSearch, getConversationLookup, getSelectedConversationKey, getSelectedMessage], [getSearch, getConversationLookup, getSelectedConversationKey],
( (state: SearchStateType, lookup: ConversationLookupType, selectedConversation?: string) => {
state: SearchStateType,
lookup: ConversationLookupType,
selectedConversation?: string,
selectedMessage?: string
) => {
return { return {
contacts: compact( contacts: compact(
state.contacts.map(id => { state.contacts.map(id => {
@ -65,16 +60,7 @@ export const getSearchResults = createSelector(
}) })
), ),
hideMessagesHeader: false, hideMessagesHeader: false,
messages: state.messages.map(message => {
if (message.id === selectedMessage) {
return {
...message,
isSelected: true,
};
}
return message;
}),
searchTerm: state.query, searchTerm: state.query,
}; };
} }

Loading…
Cancel
Save