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

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