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.

AbstractChatMessage.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }