Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ChatMessage.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import Message from '../../../base/react/components/web/Message';
  5. import { connect } from '../../../base/redux';
  6. import { MESSAGE_TYPE_LOCAL } from '../../constants';
  7. import AbstractChatMessage, { type Props } from '../AbstractChatMessage';
  8. import PrivateMessageButton from './PrivateMessageButton';
  9. /**
  10. * Renders a single chat message.
  11. */
  12. class ChatMessage extends AbstractChatMessage<Props> {
  13. /**
  14. * Implements React's {@link Component#render()}.
  15. *
  16. * @inheritdoc
  17. * @returns {ReactElement}
  18. */
  19. render() {
  20. const { message, t, knocking } = this.props;
  21. return (
  22. <div
  23. className = 'chatmessage-wrapper'
  24. tabIndex = { -1 }>
  25. <div
  26. className = { `chatmessage ${message.privateMessage ? 'privatemessage' : ''} ${
  27. message.lobbyChat && !knocking ? 'lobbymessage' : ''}` }>
  28. <div className = 'replywrapper'>
  29. <div className = 'messagecontent'>
  30. { this.props.showDisplayName && this._renderDisplayName() }
  31. <div className = 'usermessage'>
  32. <span className = 'sr-only'>
  33. { this.props.message.displayName === this.props.message.recipient
  34. ? t('chat.messageAccessibleTitleMe')
  35. : t('chat.messageAccessibleTitle',
  36. { user: this.props.message.displayName }) }
  37. </span>
  38. <Message text = { this._getMessageText() } />
  39. </div>
  40. { (message.privateMessage || (message.lobbyChat && !knocking))
  41. && this._renderPrivateNotice() }
  42. </div>
  43. { (message.privateMessage || (message.lobbyChat && !knocking))
  44. && message.messageType !== MESSAGE_TYPE_LOCAL
  45. && (
  46. <div
  47. className = { `messageactions ${
  48. message.lobbyChat ? 'lobbychatmessageactions' : ''}` }>
  49. <PrivateMessageButton
  50. isLobbyMessage = { message.lobbyChat }
  51. participantID = { message.id }
  52. reply = { true }
  53. showLabel = { false } />
  54. </div>
  55. ) }
  56. </div>
  57. </div>
  58. { this.props.showTimestamp && this._renderTimestamp() }
  59. </div>
  60. );
  61. }
  62. _getFormattedTimestamp: () => string;
  63. _getMessageText: () => string;
  64. _getPrivateNoticeMessage: () => string;
  65. /**
  66. * Renders the display name of the sender.
  67. *
  68. * @returns {React$Element<*>}
  69. */
  70. _renderDisplayName() {
  71. return (
  72. <div
  73. aria-hidden = { true }
  74. className = 'display-name'>
  75. { this.props.message.displayName }
  76. </div>
  77. );
  78. }
  79. /**
  80. * Renders the message privacy notice.
  81. *
  82. * @returns {React$Element<*>}
  83. */
  84. _renderPrivateNotice() {
  85. return (
  86. <div className = 'privatemessagenotice'>
  87. { this._getPrivateNoticeMessage() }
  88. </div>
  89. );
  90. }
  91. /**
  92. * Renders the time at which the message was sent.
  93. *
  94. * @returns {React$Element<*>}
  95. */
  96. _renderTimestamp() {
  97. return (
  98. <div className = 'timestamp'>
  99. { this._getFormattedTimestamp() }
  100. </div>
  101. );
  102. }
  103. }
  104. /**
  105. * Maps part of the Redux store to the props of this component.
  106. *
  107. * @param {Object} state - The Redux state.
  108. * @returns {Props}
  109. */
  110. function _mapStateToProps(state: Object): $Shape<Props> {
  111. const { knocking } = state['features/lobby'];
  112. return {
  113. knocking
  114. };
  115. }
  116. export default translate(connect(_mapStateToProps)(ChatMessage));