feat: fixed click on a quote to go to the original message

added animation support to attachments when opening it via a quote
pull/2757/head
William Grant 2 years ago
parent ab028307f4
commit acdeabf306

@ -16,7 +16,7 @@ import { MessageLinkPreview } from './MessageLinkPreview';
import { MessageQuote } from './MessageQuote'; import { MessageQuote } from './MessageQuote';
import { MessageText } from './MessageText'; import { MessageText } from './MessageText';
import { ScrollToLoadedMessageContext } from '../../SessionMessagesListContainer'; import { ScrollToLoadedMessageContext } from '../../SessionMessagesListContainer';
import styled, { css } from 'styled-components'; import styled, { css, keyframes } from 'styled-components';
export type MessageContentSelectorProps = Pick< export type MessageContentSelectorProps = Pick<
MessageRenderingProps, MessageRenderingProps,
@ -44,19 +44,7 @@ function onClickOnMessageInnerContainer(event: React.MouseEvent<HTMLDivElement>)
const StyledMessageContent = styled.div``; const StyledMessageContent = styled.div``;
const StyledMessageOpaqueContent = styled.div<{ const opacityAnimation = keyframes`
messageDirection: MessageModelType;
highlight: boolean;
}>`
background: ${props =>
props.messageDirection === 'incoming'
? 'var(--message-bubbles-received-background-color)'
: 'var(--message-bubbles-sent-background-color)'};
align-self: ${props => (props.messageDirection === 'incoming' ? 'flex-start' : 'flex-end')};
padding: var(--padding-message-content);
border-radius: var(--border-radius-message-box);
@keyframes highlight {
0% { 0% {
opacity: 1; opacity: 1;
} }
@ -72,19 +60,29 @@ const StyledMessageOpaqueContent = styled.div<{
100% { 100% {
opacity: 1; opacity: 1;
} }
} `;
${props => { const StyledMessageHighlighter = styled.div<{
return ( highlight: boolean;
props.highlight && }>`
css` ${props =>
animation-name: highlight; props.highlight &&
animation-timing-function: linear; css`
animation-duration: 1s; animation: ${opacityAnimation} 1s linear;
border-radius: 'var(--border-radius-message-box)'; `}
` `;
);
}} const StyledMessageOpaqueContent = styled(StyledMessageHighlighter)<{
messageDirection: MessageModelType;
highlight: boolean;
}>`
background: ${props =>
props.messageDirection === 'incoming'
? 'var(--message-bubbles-received-background-color)'
: 'var(--message-bubbles-sent-background-color)'};
align-self: ${props => (props.messageDirection === 'incoming' ? 'flex-start' : 'flex-end')};
padding: var(--padding-message-content);
border-radius: var(--border-radius-message-box);
`; `;
export const IsMessageVisibleContext = createContext(false); export const IsMessageVisibleContext = createContext(false);
@ -195,11 +193,13 @@ export const MessageContent = (props: Props) => {
</StyledMessageOpaqueContent> </StyledMessageOpaqueContent>
)} )}
{!isDeleted && ( {!isDeleted && (
<MessageAttachment <StyledMessageHighlighter highlight={highlight}>
messageId={props.messageId} <MessageAttachment
imageBroken={imageBroken} messageId={props.messageId}
handleImageError={handleImageError} imageBroken={imageBroken}
/> handleImageError={handleImageError}
/>
</StyledMessageHighlighter>
)} )}
</IsMessageVisibleContext.Provider> </IsMessageVisibleContext.Provider>
</InView> </InView>

@ -11,8 +11,6 @@ import {
} from '../../../../state/selectors/conversations'; } from '../../../../state/selectors/conversations';
import { Quote } from './quote/Quote'; import { Quote } from './quote/Quote';
import { ToastUtils } from '../../../../session/utils'; import { ToastUtils } from '../../../../session/utils';
import { Data } from '../../../../data/data';
import { MessageModel } from '../../../../models/message';
// tslint:disable: use-simple-attributes // tslint:disable: use-simple-attributes
@ -43,8 +41,9 @@ export const MessageQuote = (props: Props) => {
sender: quoteAuthor, sender: quoteAuthor,
authorProfileName, authorProfileName,
authorName, authorName,
messageId: quotedMessageSentAt, messageId: quotedMessageId,
referencedMessageNotFound, referencedMessageNotFound,
convoId,
} = quote; } = quote;
const quoteText = text || null; const quoteText = text || null;
@ -70,32 +69,26 @@ export const MessageQuote = (props: Props) => {
// For simplicity's sake, we show the 'not found' toast no matter what if we were // For simplicity's sake, we show the 'not found' toast no matter what if we were
// not able to find the referenced message when the quote was received. // not able to find the referenced message when the quote was received.
if (quoteNotFound || !quotedMessageSentAt || !quoteAuthor) { if (quoteNotFound || !quotedMessageId || !quoteAuthor || !convoId) {
ToastUtils.pushOriginalNotFound();
return;
}
// TODO Should no longer have to do this lookup?
// Can just use referencedMessageNotFound?
const collection = await Data.getMessagesBySentAt(_.toNumber(quotedMessageSentAt));
const foundInDb = collection.find((item: MessageModel) => {
const messageAuthor = item.get('source');
return Boolean(messageAuthor && quoteAuthor === messageAuthor);
});
if (!foundInDb) {
ToastUtils.pushOriginalNotFound(); ToastUtils.pushOriginalNotFound();
return; return;
} }
void openConversationToSpecificMessage({ void openConversationToSpecificMessage({
conversationKey: foundInDb.get('conversationId'), conversationKey: convoId,
messageIdToNavigateTo: foundInDb.get('id'), messageIdToNavigateTo: quotedMessageId,
shouldHighlightMessage: true, shouldHighlightMessage: true,
}); });
}, },
[quote, multiSelectMode, props.messageId] [
convoId,
isMessageDetailViewMode,
multiSelectMode,
quote,
quoteNotFound,
quotedMessageId,
quoteAuthor,
]
); );
return ( return (

@ -1451,6 +1451,7 @@ export function overrideWithSourceMessage(
authorName, authorName,
messageId: msgProps.id || quote.messageId, messageId: msgProps.id || quote.messageId,
referencedMessageNotFound: false, referencedMessageNotFound: false,
convoId: convo.id,
}; };
return quoteProps; return quoteProps;

@ -173,6 +173,7 @@ export type PropsForQuote = {
authorName?: string; authorName?: string;
messageId?: string; messageId?: string;
referencedMessageNotFound?: boolean; referencedMessageNotFound?: boolean;
convoId?: string;
}; };
export type PropsForMessageWithoutConvoProps = { export type PropsForMessageWithoutConvoProps = {
@ -382,10 +383,6 @@ async function getMessages({
const id = quotes[i].propsForMessage?.quote?.messageId; const id = quotes[i].propsForMessage?.quote?.messageId;
const sender = quotes[i].propsForMessage.quote?.sender; const sender = quotes[i].propsForMessage.quote?.sender;
// TODO use this is the renderering process
// const contact = message.findAndFormatContact(author);
// const authorName = contact?.profileName || contact?.name || '';
if (id && sender) { if (id && sender) {
const timestamp = Number(id); const timestamp = Number(id);
// See if a quoted message is already in memory if not lookup in db // See if a quoted message is already in memory if not lookup in db

@ -991,7 +991,6 @@ export const getMessageQuoteProps = createSelector(
quote = overrideWithSourceMessage(quote, sourceMessage); quote = overrideWithSourceMessage(quote, sourceMessage);
} }
window.log.debug(`WIP: quote`, quote);
return { direction, quote }; return { direction, quote };
} }
); );

Loading…
Cancel
Save