2019-05-03 19:41:09 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import ChatMessage from './ChatMessage';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Additional CSS classes to apply to the root element.
|
|
|
|
*/
|
|
|
|
className: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The messages to display as a group.
|
|
|
|
*/
|
|
|
|
messages: Array<Object>,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a list of chat messages. Will show only the display name for the
|
|
|
|
* first chat message and the timestamp for the last chat message.
|
|
|
|
*
|
|
|
|
* @extends React.Component
|
|
|
|
*/
|
|
|
|
class ChatMessageGroup extends Component<Props> {
|
|
|
|
static defaultProps = {
|
|
|
|
className: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { className, messages } = this.props;
|
|
|
|
|
|
|
|
const messagesLength = messages.length;
|
|
|
|
|
|
|
|
if (!messagesLength) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = { `chat-message-group ${className}` }>
|
|
|
|
{
|
|
|
|
messages.map((message, i) => (
|
2019-05-09 14:50:36 +00:00
|
|
|
<ChatMessage
|
|
|
|
key = { i }
|
|
|
|
message = { message }
|
2019-05-06 19:30:38 +00:00
|
|
|
showDisplayName = { i === 0 }
|
|
|
|
showTimestamp = { i === messages.length - 1 } />
|
2019-05-09 14:50:36 +00:00
|
|
|
))
|
2019-05-03 19:41:09 +00:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChatMessageGroup;
|