signal-desktop/ts/state/smart/MessageDetail.tsx

101 lines
2.5 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { connect } from 'react-redux';
import type { ExternalProps as MessageDetailProps } from '../../components/conversation/MessageDetail';
import { MessageDetail } from '../../components/conversation/MessageDetail';
import { mapDispatchToProps } from '../actions';
import type { StateType } from '../reducer';
import { getPreferredBadgeSelector } from '../selectors/badges';
import { getIntl, getInteractionMode, getTheme } from '../selectors/user';
import { renderAudioAttachment } from './renderAudioAttachment';
2021-06-07 16:50:18 +00:00
import { getContactNameColorSelector } from '../selectors/conversations';
2022-10-03 23:43:44 +00:00
import { markViewed } from '../ducks/conversations';
2021-05-10 22:38:18 +00:00
export { Contact } from '../../components/conversation/MessageDetail';
2021-08-30 21:32:56 +00:00
export type OwnProps = Omit<
MessageDetailProps,
| 'getPreferredBadge'
| 'i18n'
| 'interactionMode'
| 'renderAudioAttachment'
| 'renderEmojiPicker'
| 'renderReactionPicker'
| 'theme'
2022-10-03 23:43:44 +00:00
| 'markViewed'
>;
const mapStateToProps = (
state: StateType,
props: OwnProps
): MessageDetailProps => {
const {
contacts,
errors,
message,
receivedAt,
sentAt,
showSafetyNumber,
displayTapToViewMessage,
kickOffAttachmentDownload,
markAttachmentAsCorrupted,
openConversation,
2022-05-11 20:59:58 +00:00
openGiftBadge,
openLink,
showContactDetail,
showContactModal,
showExpiredIncomingTapToViewToast,
showExpiredOutgoingTapToViewToast,
showVisualAttachment,
startConversation,
} = props;
2021-06-07 16:50:18 +00:00
const contactNameColor =
message.conversationType === 'group'
? getContactNameColorSelector(state)(
message.conversationId,
message.author.id
)
: undefined;
const getPreferredBadge = getPreferredBadgeSelector(state);
return {
contacts,
2021-06-07 16:50:18 +00:00
contactNameColor,
errors,
message,
receivedAt,
sentAt,
getPreferredBadge,
i18n: getIntl(state),
interactionMode: getInteractionMode(state),
theme: getTheme(state),
showSafetyNumber,
displayTapToViewMessage,
kickOffAttachmentDownload,
markAttachmentAsCorrupted,
markViewed,
openConversation,
2022-05-11 20:59:58 +00:00
openGiftBadge,
openLink,
renderAudioAttachment,
showContactDetail,
showContactModal,
showExpiredIncomingTapToViewToast,
showExpiredOutgoingTapToViewToast,
showVisualAttachment,
startConversation,
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartMessageDetail = smart(MessageDetail);