import React from 'react'; import classNames from 'classnames'; import { MessageDirection } from '../../models/messageType'; import { getOurPubKeyStrFromCache } from '../../session/utils/User'; import { FindAndFormatContactType, openConversationWithMessages, } from '../../state/ducks/conversations'; import { ContactName } from '../conversation/ContactName'; import { Avatar, AvatarSize } from '../avatar/Avatar'; import { Timestamp } from '../conversation/Timestamp'; import { MessageBodyHighlight } from '../basic/MessageBodyHighlight'; type PropsHousekeeping = { isSelected?: boolean; }; export type PropsForSearchResults = { from: FindAndFormatContactType; to: FindAndFormatContactType; id: string; conversationId: string; destination: string; source: string; direction?: string; snippet?: string; //not sure about the type of snippet receivedAt?: number; }; export type MessageResultProps = PropsForSearchResults & PropsHousekeeping; const FromName = (props: { source: string; destination: string }) => { const { source, destination } = props; const isNoteToSelf = destination === getOurPubKeyStrFromCache() && source === destination; if (isNoteToSelf) { return ( {window.i18n('noteToSelf')} ); } if (source === getOurPubKeyStrFromCache()) { return {window.i18n('you')}; } return ( // tslint:disable: use-simple-attributes ); }; const From = (props: { source: string; destination: string }) => { const { source, destination } = props; const fromName = ; const ourKey = getOurPubKeyStrFromCache(); if (destination !== ourKey) { return (
{fromName} {window.i18n('to')}
); } return
{fromName}
; }; const AvatarItem = (props: { source: string }) => { const { source } = props; return ; }; export const MessageSearchResult = (props: MessageResultProps) => { const { isSelected, id, conversationId, receivedAt, snippet, destination, source, direction, } = props; // Some messages miss a source or destination. Doing checks to see if the fields can be derived from other sources. // E.g. if the source is missing but the message is outgoing, the source will be our pubkey const sourceOrDestinationDerivable = (destination && direction === MessageDirection.outgoing) || !destination || !source || (source && direction === MessageDirection.incoming); if (!sourceOrDestinationDerivable) { return null; } const effectiveSource = !source && direction === MessageDirection.outgoing ? getOurPubKeyStrFromCache() : source; const effectiveDestination = !destination && direction === MessageDirection.incoming ? getOurPubKeyStrFromCache() : destination; return (
{ await openConversationWithMessages({ conversationKey: conversationId, messageId: id, }); }} className={classNames( 'module-message-search-result', isSelected ? 'module-message-search-result--is-selected' : null )} >
); };