update search result to have sender on the msg line

pull/2142/head
Audric Ackermann 3 years ago
parent 1eba9dce30
commit 280128ec43
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -172,7 +172,7 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
onContextMenu={onContextMenu} onContextMenu={onContextMenu}
className={className} className={className}
as="div" as="div"
threshold={0.5} threshold={0.8}
delay={isAppFocused ? 100 : 200} delay={isAppFocused ? 100 : 200}
onChange={isAppFocused ? onVisible : noop} onChange={isAppFocused ? onVisible : noop}
triggerOnce={false} triggerOnce={false}

@ -2,38 +2,40 @@ import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { getOurPubKeyStrFromCache } from '../../session/utils/User'; import { getOurPubKeyStrFromCache } from '../../session/utils/User';
import { import { openConversationToSpecificMessage } from '../../state/ducks/conversations';
FindAndFormatContactType,
openConversationToSpecificMessage,
} from '../../state/ducks/conversations';
import { ContactName } from '../conversation/ContactName'; import { ContactName } from '../conversation/ContactName';
import { Avatar, AvatarSize } from '../avatar/Avatar'; import { Avatar, AvatarSize } from '../avatar/Avatar';
import { Timestamp } from '../conversation/Timestamp'; import { Timestamp } from '../conversation/Timestamp';
import { MessageBodyHighlight } from '../basic/MessageBodyHighlight'; import { MessageBodyHighlight } from '../basic/MessageBodyHighlight';
import styled from 'styled-components'; import styled from 'styled-components';
import { MessageAttributes } from '../../models/messageType'; import { MessageAttributes } from '../../models/messageType';
import { useIsPrivate } from '../../hooks/useParamSelector'; import { useConversationUsername, useIsPrivate } from '../../hooks/useParamSelector';
import { UserUtils } from '../../session/utils'; import { UserUtils } from '../../session/utils';
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 = MessageAttributes & { snippet: string }; export type MessageResultProps = MessageAttributes & { snippet: string };
const FromName = (props: { source: string; destination: string }) => { const StyledConversationTitleResults = styled.div`
const { source, destination } = props; flex-grow: 1;
flex-shrink: 1;
font-size: 14px;
line-height: 18px;
overflow-x: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: var(--color-text);
`;
const StyledConversationFromUserInGroup = styled(StyledConversationTitleResults)`
display: inline;
font-size: 12px;
line-height: 14px;
overflow-x: hidden;
`;
const FromName = (props: { source: string; conversationId: string }) => {
const { conversationId, source } = props;
const isNoteToSelf = destination === getOurPubKeyStrFromCache() && source === destination; const isNoteToSelf = conversationId === getOurPubKeyStrFromCache() && source === conversationId;
if (isNoteToSelf) { if (isNoteToSelf) {
return ( return (
@ -48,33 +50,50 @@ const FromName = (props: { source: string; destination: string }) => {
} }
return ( return (
// tslint:disable: use-simple-attributes
<ContactName <ContactName
pubkey={source} pubkey={conversationId}
module="module-message-search-result__header__name" module="module-message-search-result__header__name"
shouldShowPubkey={false} shouldShowPubkey={false}
/> />
); );
}; };
const From = (props: { source: string; destination: string }) => { const ConversationHeader = (props: { source: string; conversationId: string }) => {
const { source, destination } = props; const { source, conversationId } = props;
const fromName = <FromName source={source} destination={destination} />; const fromName = <FromName source={source} conversationId={conversationId} />;
const ourKey = getOurPubKeyStrFromCache(); const ourKey = getOurPubKeyStrFromCache();
if (destination !== ourKey) { if (conversationId !== ourKey) {
return ( return (
<div className="module-message-search-result__header__from"> <StyledConversationTitleResults>
{fromName} {window.i18n('to')}
<span className="module-messages-search-result__header__group"> <span className="module-messages-search-result__header__group">
<ContactName pubkey={destination} shouldShowPubkey={false} /> <ContactName pubkey={conversationId} shouldShowPubkey={false} />
</span> </span>
</div> </StyledConversationTitleResults>
); );
} }
return <div className="module-message-search-result__header__from">{fromName}</div>; return <StyledConversationTitleResults>{fromName}</StyledConversationTitleResults>;
};
const FromUserInGroup = (props: { authorPubkey: string; conversationId: string }) => {
const { authorPubkey, conversationId } = props;
const ourKey = getOurPubKeyStrFromCache();
const convoIsPrivate = useIsPrivate(conversationId);
const authorConvoName = useConversationUsername(authorPubkey);
if (convoIsPrivate) {
return null;
}
if (authorPubkey === ourKey) {
return (
<StyledConversationFromUserInGroup>{window.i18n('you')}: </StyledConversationFromUserInGroup>
);
}
return <StyledConversationFromUserInGroup>{authorConvoName}: </StyledConversationFromUserInGroup>;
}; };
const AvatarItem = (props: { source: string }) => { const AvatarItem = (props: { source: string }) => {
@ -83,7 +102,6 @@ const AvatarItem = (props: { source: string }) => {
const ResultBody = styled.div` const ResultBody = styled.div`
margin-top: 1px; margin-top: 1px;
flex-grow: 1;
flex-shrink: 1; flex-shrink: 1;
font-size: 13px; font-size: 13px;
@ -94,7 +112,7 @@ const ResultBody = styled.div`
overflow: hidden; overflow: hidden;
display: -webkit-box; display: -webkit-box;
-webkit-line-clamp: 2; -webkit-line-clamp: 1;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
`; `;
@ -123,8 +141,8 @@ export const MessageSearchResult = (props: MessageResultProps) => {
* - the conversationID for a public group * - the conversationID for a public group
*/ */
const me = UserUtils.getOurPubKeyStrFromCache(); const me = UserUtils.getOurPubKeyStrFromCache();
const convoIsPrivate = useIsPrivate(conversationId); const convoIsPrivate = useIsPrivate(conversationId);
const destination = const destination =
direction === 'incoming' ? conversationId : convoIsPrivate ? me : conversationId; direction === 'incoming' ? conversationId : convoIsPrivate ? me : conversationId;
@ -145,15 +163,16 @@ export const MessageSearchResult = (props: MessageResultProps) => {
}} }}
className={classNames('module-message-search-result')} className={classNames('module-message-search-result')}
> >
<AvatarItem source={source || me} /> <AvatarItem source={conversationId} />
<div className="module-message-search-result__text"> <div className="module-message-search-result__text">
<div className="module-message-search-result__header"> <div className="module-message-search-result__header">
<From source={source} destination={destination} /> <ConversationHeader source={destination} conversationId={conversationId} />
<div className="module-message-search-result__header__timestamp"> <div className="module-message-search-result__header__timestamp">
<Timestamp timestamp={serverTimestamp || timestamp || sent_at || received_at} /> <Timestamp timestamp={serverTimestamp || timestamp || sent_at || received_at} />
</div> </div>
</div> </div>
<ResultBody> <ResultBody>
<FromUserInGroup authorPubkey={source} conversationId={conversationId} />
<MessageBodyHighlight text={snippet || ''} /> <MessageBodyHighlight text={snippet || ''} />
</ResultBody> </ResultBody>
</div> </div>

Loading…
Cancel
Save