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';
|
|
|
|
import { Timeline } from '../../components/conversation/Timeline';
|
|
|
|
import { StateType } from '../reducer';
|
|
|
|
|
|
|
|
import { getIntl } from '../selectors/user';
|
2019-05-31 22:42:01 +00:00
|
|
|
import {
|
|
|
|
getConversationMessagesSelector,
|
|
|
|
getConversationSelector,
|
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';
|
|
|
|
import { SmartTimelineLoadingRow } from './TimelineLoadingRow';
|
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
|
|
|
|
const FilteredSmartTimelineItem = SmartTimelineItem as any;
|
2019-05-31 22:42:01 +00:00
|
|
|
const FilteredSmartTypingBubble = SmartTypingBubble as any;
|
|
|
|
const FilteredSmartLastSeenIndicator = SmartLastSeenIndicator as any;
|
|
|
|
const FilteredSmartTimelineLoadingRow = SmartTimelineLoadingRow as 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
|
|
|
};
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
function renderItem(
|
|
|
|
messageId: string,
|
|
|
|
conversationId: string,
|
|
|
|
actionProps: Object
|
|
|
|
): JSX.Element {
|
|
|
|
return (
|
|
|
|
<FilteredSmartTimelineItem
|
|
|
|
{...actionProps}
|
|
|
|
conversationId={conversationId}
|
|
|
|
id={messageId}
|
|
|
|
/>
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
function renderLastSeenIndicator(id: string): JSX.Element {
|
|
|
|
return <FilteredSmartLastSeenIndicator id={id} />;
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
...pick(conversation, ['unreadCount', 'typingContact']),
|
|
|
|
...conversationMessages,
|
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,
|
|
|
|
renderLoadingRow,
|
|
|
|
renderTypingBubble,
|
|
|
|
...actions,
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export const SmartTimeline = smart(Timeline);
|