您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ChatMessageGroup.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. <ChatMessage
  42. key = { i }
  43. message = { message }
  44. showDisplayName = { i === 0 } />
  45. ))
  46. }
  47. <div className = 'chat-message-group-footer'>
  48. { getLocalizedDateFormatter(
  49. new Date(timestamp)).format('H:mm') }
  50. </div>
  51. </div>
  52. );
  53. }
  54. }
  55. export default ChatMessageGroup;