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

@ -1036,7 +1036,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
(m: any) => m.get('received_at') > newestUnreadDate
);
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) {

@ -37,7 +37,6 @@ import {
PropsForGroupUpdateName,
PropsForGroupUpdateRemove,
PropsForMessageWithoutConvoProps,
PropsForSearchResults,
} from '../state/ducks/conversations';
import { VisibleMessage } from '../session/messages/outgoing/visibleMessage/VisibleMessage';
import { buildSyncMessage } from '../session/utils/syncUtils';
@ -88,7 +87,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
perfStart(`getPropsMessage-${this.id}`);
const messageProps: MessageModelPropsWithoutConvoProps = {
propsForMessage: this.getPropsForMessage(),
propsForSearchResult: this.getPropsForSearchResult(),
propsForDataExtractionNotification: this.getPropsForDataExtractionNotification(),
propsForGroupInvitation: this.getPropsForGroupInvitation(),
propsForGroupNotification: this.getPropsForGroupNotification(),
@ -497,25 +495,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
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 {
const sender = this.getSource();
const expirationLength = this.get('expireTimer') * 1000;

@ -19,7 +19,6 @@ import { omit } from 'lodash';
export type MessageModelPropsWithoutConvoProps = {
propsForMessage: PropsForMessageWithoutConvoProps;
propsForSearchResult: PropsForSearchResults | null;
propsForGroupInvitation: PropsForGroupInvitation | null;
propsForTimerNotification: PropsForExpirationTimer | null;
propsForDataExtractionNotification: PropsForDataExtractionNotification | null;
@ -128,16 +127,6 @@ export type PropsForGroupInvitation = {
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 = {
id: number;
contentType: string;

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

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

Loading…
Cancel
Save