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

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