2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2019-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
import { pick } from 'lodash';
|
2019-03-20 17:42:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-03-10 20:36:58 +00:00
|
|
|
import { GlobalAudioContext } from '../../components/GlobalAudioContext';
|
2019-03-20 17:42:28 +00:00
|
|
|
import { Timeline } from '../../components/conversation/Timeline';
|
2020-05-05 19:49:34 +00:00
|
|
|
import { RenderEmojiPickerProps } from '../../components/conversation/ReactionPicker';
|
2019-03-20 17:42:28 +00:00
|
|
|
import { StateType } from '../reducer';
|
|
|
|
|
|
|
|
import { getIntl } from '../selectors/user';
|
2019-05-31 22:42:01 +00:00
|
|
|
import {
|
|
|
|
getConversationMessagesSelector,
|
|
|
|
getConversationSelector,
|
2021-03-03 20:09:58 +00:00
|
|
|
getInvitedContactsForNewlyCreatedGroup,
|
2019-11-07 21:36:16 +00:00
|
|
|
getSelectedMessage,
|
2019-05-31 22:42:01 +00:00
|
|
|
} from '../selectors/conversations';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
import { SmartTimelineItem } from './TimelineItem';
|
2019-05-31 22:42:01 +00:00
|
|
|
import { SmartTypingBubble } from './TypingBubble';
|
|
|
|
import { SmartLastSeenIndicator } from './LastSeenIndicator';
|
2020-05-27 21:37:06 +00:00
|
|
|
import { SmartHeroRow } from './HeroRow';
|
2019-05-31 22:42:01 +00:00
|
|
|
import { SmartTimelineLoadingRow } from './TimelineLoadingRow';
|
2020-05-05 19:49:34 +00:00
|
|
|
import { SmartEmojiPicker } from './EmojiPicker';
|
2021-03-10 20:36:58 +00:00
|
|
|
import { SmartMessageAudio, Props as MessageAudioProps } from './MessageAudio';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
// Workaround: A react component's required properties are filtering up through connect()
|
|
|
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31363
|
2020-09-14 21:56:35 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2019-03-20 17:42:28 +00:00
|
|
|
const FilteredSmartTimelineItem = SmartTimelineItem as any;
|
2019-05-31 22:42:01 +00:00
|
|
|
const FilteredSmartTypingBubble = SmartTypingBubble as any;
|
|
|
|
const FilteredSmartLastSeenIndicator = SmartLastSeenIndicator as any;
|
2020-05-27 21:37:06 +00:00
|
|
|
const FilteredSmartHeroRow = SmartHeroRow as any;
|
2019-05-31 22:42:01 +00:00
|
|
|
const FilteredSmartTimelineLoadingRow = SmartTimelineLoadingRow as any;
|
2020-09-14 21:56:35 +00:00
|
|
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
type ExternalProps = {
|
|
|
|
id: string;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
// Note: most action creators are not wired into redux; for now they
|
|
|
|
// are provided by ConversationView in setupTimeline().
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
|
2021-03-10 20:36:58 +00:00
|
|
|
type AudioAttachmentProps = Omit<
|
|
|
|
MessageAudioProps,
|
|
|
|
'audio' | 'audioContext' | 'waveformCache'
|
|
|
|
>;
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
function renderItem(
|
|
|
|
messageId: string,
|
|
|
|
conversationId: string,
|
2020-09-14 21:56:35 +00:00
|
|
|
actionProps: Record<string, unknown>
|
2019-11-07 21:36:16 +00:00
|
|
|
): JSX.Element {
|
|
|
|
return (
|
|
|
|
<FilteredSmartTimelineItem
|
|
|
|
{...actionProps}
|
|
|
|
conversationId={conversationId}
|
|
|
|
id={messageId}
|
2020-05-05 19:49:34 +00:00
|
|
|
renderEmojiPicker={renderEmojiPicker}
|
2021-03-10 20:36:58 +00:00
|
|
|
renderAudioAttachment={renderAudioAttachment}
|
2020-05-05 19:49:34 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2021-03-10 20:36:58 +00:00
|
|
|
|
|
|
|
function renderAudioAttachment(props: AudioAttachmentProps) {
|
|
|
|
return (
|
|
|
|
<GlobalAudioContext.Consumer>
|
|
|
|
{globalAudioProps => {
|
|
|
|
return (
|
|
|
|
globalAudioProps && (
|
|
|
|
<SmartMessageAudio {...props} {...globalAudioProps} />
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</GlobalAudioContext.Consumer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-05 19:49:34 +00:00
|
|
|
function renderEmojiPicker({
|
|
|
|
ref,
|
|
|
|
onPickEmoji,
|
|
|
|
onClose,
|
|
|
|
style,
|
|
|
|
}: RenderEmojiPickerProps): JSX.Element {
|
|
|
|
return (
|
|
|
|
<SmartEmojiPicker
|
|
|
|
ref={ref}
|
|
|
|
onPickEmoji={onPickEmoji}
|
|
|
|
onClose={onClose}
|
|
|
|
style={style}
|
2019-11-07 21:36:16 +00:00
|
|
|
/>
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
function renderLastSeenIndicator(id: string): JSX.Element {
|
|
|
|
return <FilteredSmartLastSeenIndicator id={id} />;
|
|
|
|
}
|
2020-08-07 00:50:54 +00:00
|
|
|
function renderHeroRow(
|
|
|
|
id: string,
|
|
|
|
onHeightChange: () => unknown,
|
|
|
|
updateSharedGroups: () => unknown
|
|
|
|
): JSX.Element {
|
|
|
|
return (
|
|
|
|
<FilteredSmartHeroRow
|
|
|
|
id={id}
|
|
|
|
onHeightChange={onHeightChange}
|
|
|
|
updateSharedGroups={updateSharedGroups}
|
|
|
|
/>
|
|
|
|
);
|
2020-05-27 21:37:06 +00:00
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function renderLoadingRow(id: string): JSX.Element {
|
|
|
|
return <FilteredSmartTimelineLoadingRow id={id} />;
|
|
|
|
}
|
|
|
|
function renderTypingBubble(id: string): JSX.Element {
|
|
|
|
return <FilteredSmartTypingBubble id={id} />;
|
|
|
|
}
|
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
2019-05-31 22:42:01 +00:00
|
|
|
const { id, ...actions } = props;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
const conversation = getConversationSelector(state)(id);
|
|
|
|
const conversationMessages = getConversationMessagesSelector(state)(id);
|
2019-11-07 21:36:16 +00:00
|
|
|
const selectedMessage = getSelectedMessage(state);
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
return {
|
2019-05-31 22:42:01 +00:00
|
|
|
id,
|
2020-12-01 16:42:35 +00:00
|
|
|
...pick(conversation, [
|
|
|
|
'unreadCount',
|
|
|
|
'typingContact',
|
|
|
|
'isGroupV1AndDisabled',
|
|
|
|
]),
|
2019-05-31 22:42:01 +00:00
|
|
|
...conversationMessages,
|
2021-03-03 20:09:58 +00:00
|
|
|
invitedContactsForNewlyCreatedGroup: getInvitedContactsForNewlyCreatedGroup(
|
|
|
|
state
|
|
|
|
),
|
2019-11-07 21:36:16 +00:00
|
|
|
selectedMessageId: selectedMessage ? selectedMessage.id : undefined,
|
2019-03-20 17:42:28 +00:00
|
|
|
i18n: getIntl(state),
|
2019-05-31 22:42:01 +00:00
|
|
|
renderItem,
|
|
|
|
renderLastSeenIndicator,
|
2020-05-27 21:37:06 +00:00
|
|
|
renderHeroRow,
|
2019-05-31 22:42:01 +00:00
|
|
|
renderLoadingRow,
|
|
|
|
renderTypingBubble,
|
|
|
|
...actions,
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
export const SmartTimeline = smart(Timeline as any);
|