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

74 lines
1.8 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';
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'
| 'showContactModal'
| 'showConversation'
>;
const mapStateToProps = (
state: StateType,
props: OwnProps
): MessageDetailProps => {
const {
contacts,
errors,
message,
receivedAt,
sentAt,
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),
renderAudioAttachment,
startConversation,
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartMessageDetail = smart(MessageDetail);