You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChatMessageGroup.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // @flow
  2. import React, { Component } from 'react';
  3. import ChatMessage from './ChatMessage';
  4. type Props = {
  5. /**
  6. * Additional CSS classes to apply to the root element.
  7. */
  8. className: string,
  9. /**
  10. * The messages to display as a group.
  11. */
  12. messages: Array<Object>,
  13. };
  14. /**
  15. * Displays a list of chat messages. Will show only the display name for the
  16. * first chat message and the timestamp for the last chat message.
  17. *
  18. * @augments React.Component
  19. */
  20. class ChatMessageGroup extends Component<Props> {
  21. static defaultProps = {
  22. className: ''
  23. };
  24. /**
  25. * Implements React's {@link Component#render()}.
  26. *
  27. * @inheritdoc
  28. */
  29. render() {
  30. const { className, messages } = this.props;
  31. const messagesLength = messages.length;
  32. if (!messagesLength) {
  33. return null;
  34. }
  35. return (
  36. <div className = { `chat-message-group ${className}` }>
  37. { messages.map((message, i) => (
  38. <ChatMessage
  39. key = { i }
  40. message = { message }
  41. showDisplayName = { i === 0 }
  42. showTimestamp = { i === messages.length - 1 } />
  43. ))}
  44. </div>
  45. );
  46. }
  47. }
  48. export default ChatMessageGroup;