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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * @extends 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. {
  38. messages.map((message, i) => (
  39. <ChatMessage
  40. key = { i }
  41. message = { message }
  42. showDisplayName = { i === 0 }
  43. showTimestamp = { i === messages.length - 1 } />
  44. ))
  45. }
  46. </div>
  47. );
  48. }
  49. }
  50. export default ChatMessageGroup;