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

AbstractChatMessage.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import { PureComponent } from 'react';
  3. import { getLocalizedDateFormatter } from '../../base/i18n';
  4. /**
  5. * Formatter string to display the message timestamp.
  6. */
  7. const TIMESTAMP_FORMAT = 'H:mm';
  8. /**
  9. * The type of the React {@code Component} props of {@code AbstractChatMessage}.
  10. */
  11. export type Props = {
  12. /**
  13. * The representation of a chat message.
  14. */
  15. message: Object,
  16. /**
  17. * Whether or not the avatar image of the participant which sent the message
  18. * should be displayed.
  19. */
  20. showAvatar: boolean,
  21. /**
  22. * Whether or not the name of the participant which sent the message should
  23. * be displayed.
  24. */
  25. showDisplayName: boolean,
  26. /**
  27. * Whether or not the time at which the message was sent should be
  28. * displayed.
  29. */
  30. showTimestamp: boolean,
  31. /**
  32. * Invoked to receive translated strings.
  33. */
  34. t: Function
  35. };
  36. /**
  37. * Abstract component to display a chat message.
  38. */
  39. export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
  40. /**
  41. * Returns the timestamp to display for the message.
  42. *
  43. * @returns {string}
  44. */
  45. _getFormattedTimestamp() {
  46. return getLocalizedDateFormatter(new Date(this.props.message.timestamp))
  47. .format(TIMESTAMP_FORMAT);
  48. }
  49. /**
  50. * Generates the message text to be redered in the component.
  51. *
  52. * @returns {string}
  53. */
  54. _getMessageText() {
  55. const { message } = this.props;
  56. return message.messageType === 'error'
  57. ? this.props.t('chat.error', {
  58. error: message.message
  59. })
  60. : message.message;
  61. }
  62. /**
  63. * Returns the message that is displayed as a notice for private messages.
  64. *
  65. * @returns {string}
  66. */
  67. _getPrivateNoticeMessage() {
  68. const { message, t } = this.props;
  69. return t('chat.privateNotice', {
  70. recipient: message.messageType === 'local' ? message.recipient : t('chat.you')
  71. });
  72. }
  73. }