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.

ChatMessage.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // @flow
  2. import React from 'react';
  3. import { toArray } from 'react-emoji-render';
  4. import { translate } from '../../../base/i18n';
  5. import { Linkify } from '../../../base/react';
  6. import { MESSAGE_TYPE_LOCAL } from '../../constants';
  7. import AbstractChatMessage, {
  8. type Props
  9. } from '../AbstractChatMessage';
  10. import PrivateMessageButton from '../PrivateMessageButton';
  11. /**
  12. * Renders a single chat message.
  13. */
  14. class ChatMessage extends AbstractChatMessage<Props> {
  15. /**
  16. * Implements React's {@link Component#render()}.
  17. *
  18. * @inheritdoc
  19. * @returns {ReactElement}
  20. */
  21. render() {
  22. const { message } = this.props;
  23. const processedMessage = [];
  24. // content is an array of text and emoji components
  25. const content = toArray(this._getMessageText(), { className: 'smiley' });
  26. content.forEach(i => {
  27. if (typeof i === 'string') {
  28. processedMessage.push(<Linkify key = { i }>{ i }</Linkify>);
  29. } else {
  30. processedMessage.push(i);
  31. }
  32. });
  33. return (
  34. <div className = 'chatmessage-wrapper'>
  35. <div className = 'replywrapper'>
  36. <div className = 'chatmessage'>
  37. { this.props.showDisplayName && this._renderDisplayName() }
  38. <div className = 'usermessage'>
  39. { processedMessage }
  40. </div>
  41. { message.privateMessage && this._renderPrivateNotice() }
  42. </div>
  43. { message.privateMessage && message.messageType !== MESSAGE_TYPE_LOCAL
  44. && <PrivateMessageButton
  45. participantID = { message.id }
  46. reply = { true }
  47. showLabel = { false } /> }
  48. </div>
  49. { this.props.showTimestamp && this._renderTimestamp() }
  50. </div>
  51. );
  52. }
  53. _getFormattedTimestamp: () => string;
  54. _getMessageText: () => string;
  55. _getPrivateNoticeMessage: () => string;
  56. /**
  57. * Renders the display name of the sender.
  58. *
  59. * @returns {React$Element<*>}
  60. */
  61. _renderDisplayName() {
  62. return (
  63. <div className = 'display-name'>
  64. { this.props.message.displayName }
  65. </div>
  66. );
  67. }
  68. /**
  69. * Renders the message privacy notice.
  70. *
  71. * @returns {React$Element<*>}
  72. */
  73. _renderPrivateNotice() {
  74. return (
  75. <div className = 'privatemessagenotice'>
  76. { this._getPrivateNoticeMessage() }
  77. </div>
  78. );
  79. }
  80. /**
  81. * Renders the time at which the message was sent.
  82. *
  83. * @returns {React$Element<*>}
  84. */
  85. _renderTimestamp() {
  86. return (
  87. <div className = 'timestamp'>
  88. { this._getFormattedTimestamp() }
  89. </div>
  90. );
  91. }
  92. }
  93. export default translate(ChatMessage);