You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.3 KiB
TypeScript
97 lines
3.3 KiB
TypeScript
4 years ago
|
import classNames from 'classnames';
|
||
|
import React, { useCallback } from 'react';
|
||
|
import { useDispatch, useSelector } from 'react-redux';
|
||
|
import _ from 'underscore';
|
||
3 years ago
|
import { replyToMessage } from '../../../../interactions/conversationInteractions';
|
||
|
import { MessageRenderingProps, QuoteClickOptions } from '../../../../models/messageType';
|
||
|
import { toggleSelectedMessageId } from '../../../../state/ducks/conversations';
|
||
4 years ago
|
import {
|
||
|
getMessageContentWithStatusesSelectorProps,
|
||
|
isMessageSelectionMode,
|
||
3 years ago
|
} from '../../../../state/selectors/conversations';
|
||
|
|
||
4 years ago
|
import { MessageAuthorText } from './MessageAuthorText';
|
||
|
import { MessageContent } from './MessageContent';
|
||
|
import { MessageContextMenu } from './MessageContextMenu';
|
||
|
import { MessageStatus } from './MessageStatus';
|
||
|
|
||
4 years ago
|
export type MessageContentWithStatusSelectorProps = Pick<
|
||
|
MessageRenderingProps,
|
||
4 years ago
|
'direction' | 'isDeleted' | 'isTrustedForAttachmentDownload'
|
||
4 years ago
|
> & { hasAttachments: boolean };
|
||
4 years ago
|
|
||
|
type Props = {
|
||
|
messageId: string;
|
||
|
onQuoteClick: (quote: QuoteClickOptions) => void;
|
||
|
ctxMenuID: string;
|
||
|
isDetailView?: boolean;
|
||
|
};
|
||
|
|
||
|
export const MessageContentWithStatuses = (props: Props) => {
|
||
|
const contentProps = useSelector(state =>
|
||
|
getMessageContentWithStatusesSelectorProps(state as any, props.messageId)
|
||
|
);
|
||
|
const dispatch = useDispatch();
|
||
|
|
||
|
const multiSelectMode = useSelector(isMessageSelectionMode);
|
||
|
|
||
|
const onClickOnMessageOuterContainer = useCallback(
|
||
|
(event: React.MouseEvent<HTMLDivElement>) => {
|
||
4 years ago
|
if (multiSelectMode && messageId) {
|
||
|
event.preventDefault();
|
||
|
event.stopPropagation();
|
||
4 years ago
|
dispatch(toggleSelectedMessageId(messageId));
|
||
|
}
|
||
|
},
|
||
|
[window.contextMenuShown, props?.messageId, multiSelectMode, props?.isDetailView]
|
||
|
);
|
||
|
|
||
3 years ago
|
const onDoubleClickReplyToMessage = (e: React.MouseEvent<HTMLDivElement>) => {
|
||
|
const currentSelection = window.getSelection();
|
||
|
const currentSelectionString = currentSelection?.toString() || undefined;
|
||
|
|
||
|
// if multiple word are selected, consider that this double click was actually NOT used to reply to
|
||
|
// but to select
|
||
|
if (
|
||
|
!currentSelectionString ||
|
||
|
currentSelectionString.length === 0 ||
|
||
|
!currentSelectionString.includes(' ')
|
||
|
) {
|
||
|
void replyToMessage(messageId);
|
||
|
currentSelection?.empty();
|
||
|
e.preventDefault();
|
||
|
return;
|
||
|
}
|
||
4 years ago
|
};
|
||
|
|
||
4 years ago
|
const { messageId, onQuoteClick, ctxMenuID, isDetailView } = props;
|
||
4 years ago
|
if (!contentProps) {
|
||
|
return null;
|
||
|
}
|
||
4 years ago
|
const { direction, isDeleted, hasAttachments, isTrustedForAttachmentDownload } = contentProps;
|
||
4 years ago
|
const isIncoming = direction === 'incoming';
|
||
|
|
||
|
return (
|
||
|
<div
|
||
4 years ago
|
className={classNames('module-message', `module-message--${direction}`)}
|
||
4 years ago
|
role="button"
|
||
|
onClick={onClickOnMessageOuterContainer}
|
||
3 years ago
|
onDoubleClickCapture={onDoubleClickReplyToMessage}
|
||
4 years ago
|
style={{ width: hasAttachments && isTrustedForAttachmentDownload ? 'min-content' : 'auto' }}
|
||
4 years ago
|
>
|
||
|
<MessageStatus messageId={messageId} isCorrectSide={isIncoming} />
|
||
4 years ago
|
<div>
|
||
4 years ago
|
<MessageAuthorText messageId={messageId} />
|
||
|
|
||
|
<MessageContent
|
||
|
messageId={messageId}
|
||
|
isDetailView={isDetailView}
|
||
|
onQuoteClick={onQuoteClick}
|
||
|
/>
|
||
4 years ago
|
</div>
|
||
4 years ago
|
<MessageStatus messageId={messageId} isCorrectSide={!isIncoming} />
|
||
4 years ago
|
{!isDeleted && <MessageContextMenu messageId={messageId} contextMenuId={ctxMenuID} />}
|
||
4 years ago
|
</div>
|
||
|
);
|
||
|
};
|