|
|
|
@ -4,10 +4,14 @@ import moment from 'moment';
|
|
|
|
|
import React, { createContext, useCallback, useContext, useLayoutEffect, useState } from 'react';
|
|
|
|
|
import { InView } from 'react-intersection-observer';
|
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
import styled, { css, keyframes } from 'styled-components';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
import { MessageModelType, MessageRenderingProps } from '../../../../models/messageType';
|
|
|
|
|
import { StateType } from '../../../../state/reducer';
|
|
|
|
|
import { useHideAvatarInMsgList, useMessageIsDeleted } from '../../../../state/selectors';
|
|
|
|
|
import {
|
|
|
|
|
useHideAvatarInMsgList,
|
|
|
|
|
useMessageIsDeleted,
|
|
|
|
|
useMessageSelected,
|
|
|
|
|
} from '../../../../state/selectors';
|
|
|
|
|
import {
|
|
|
|
|
getMessageContentSelectorProps,
|
|
|
|
|
getQuotedMessageToAnimate,
|
|
|
|
@ -21,6 +25,7 @@ import { canDisplayImage } from '../../../../types/Attachment';
|
|
|
|
|
import { ScrollToLoadedMessageContext } from '../../SessionMessagesListContainer';
|
|
|
|
|
import { MessageAttachment } from './MessageAttachment';
|
|
|
|
|
import { MessageAvatar } from './MessageAvatar';
|
|
|
|
|
import { MessageHighlighter } from './MessageHighlighter';
|
|
|
|
|
import { MessageLinkPreview } from './MessageLinkPreview';
|
|
|
|
|
import { MessageQuote } from './MessageQuote';
|
|
|
|
|
import { MessageText } from './MessageText';
|
|
|
|
@ -58,37 +63,10 @@ const StyledMessageContent = styled.div<{ msgDirection: MessageModelType }>`
|
|
|
|
|
align-self: ${props => (props.msgDirection === 'incoming' ? 'flex-start' : 'flex-end')};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const opacityAnimation = keyframes`
|
|
|
|
|
0% {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
25% {
|
|
|
|
|
opacity: 0.2;
|
|
|
|
|
}
|
|
|
|
|
50% {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
75% {
|
|
|
|
|
opacity: 0.2;
|
|
|
|
|
}
|
|
|
|
|
100% {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const StyledMessageHighlighter = styled.div<{
|
|
|
|
|
highlight: boolean;
|
|
|
|
|
}>`
|
|
|
|
|
${props =>
|
|
|
|
|
props.highlight &&
|
|
|
|
|
css`
|
|
|
|
|
animation: ${opacityAnimation} 1s linear;
|
|
|
|
|
`}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledMessageOpaqueContent = styled(StyledMessageHighlighter)<{
|
|
|
|
|
const StyledMessageOpaqueContent = styled(MessageHighlighter)<{
|
|
|
|
|
isIncoming: boolean;
|
|
|
|
|
highlight: boolean;
|
|
|
|
|
selected: boolean;
|
|
|
|
|
}>`
|
|
|
|
|
background: ${props =>
|
|
|
|
|
props.isIncoming
|
|
|
|
@ -98,6 +76,8 @@ const StyledMessageOpaqueContent = styled(StyledMessageHighlighter)<{
|
|
|
|
|
padding: var(--padding-message-content);
|
|
|
|
|
border-radius: var(--border-radius-message-box);
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
|
|
${props => props.selected && `box-shadow: var(--drop-shadow);`}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const IsMessageVisibleContext = createContext(false);
|
|
|
|
@ -125,7 +105,7 @@ export const MessageContent = (props: Props) => {
|
|
|
|
|
const [imageBroken, setImageBroken] = useState(false);
|
|
|
|
|
|
|
|
|
|
const onVisible = (inView: boolean, _: IntersectionObserverEntry) => {
|
|
|
|
|
// TODO check if there is no issue with focus after simplifiying the check
|
|
|
|
|
// TODO[epic=ses-1409] check if there is no issue with focus after simplifiying the check
|
|
|
|
|
if (inView) {
|
|
|
|
|
if (isMessageVisible !== true) {
|
|
|
|
|
setMessageIsVisible(true);
|
|
|
|
@ -140,7 +120,7 @@ export const MessageContent = (props: Props) => {
|
|
|
|
|
const quotedMessageToAnimate = useSelector(getQuotedMessageToAnimate);
|
|
|
|
|
const shouldHighlightMessage = useSelector(getShouldHighlightMessage);
|
|
|
|
|
const isQuotedMessageToAnimate = quotedMessageToAnimate === props.messageId;
|
|
|
|
|
// const selected = useMessageSelected(props.messageId);
|
|
|
|
|
const selected = useMessageSelected(props.messageId);
|
|
|
|
|
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
if (isQuotedMessageToAnimate) {
|
|
|
|
@ -222,7 +202,11 @@ export const MessageContent = (props: Props) => {
|
|
|
|
|
>
|
|
|
|
|
<IsMessageVisibleContext.Provider value={isMessageVisible}>
|
|
|
|
|
{hasContentBeforeAttachment && (
|
|
|
|
|
<StyledMessageOpaqueContent isIncoming={direction === 'incoming'} highlight={highlight}>
|
|
|
|
|
<StyledMessageOpaqueContent
|
|
|
|
|
isIncoming={direction === 'incoming'}
|
|
|
|
|
highlight={highlight}
|
|
|
|
|
selected={selected}
|
|
|
|
|
>
|
|
|
|
|
{!isDeleted && (
|
|
|
|
|
<>
|
|
|
|
|
<MessageQuote messageId={props.messageId} />
|
|
|
|
|