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.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // @flow
  2. import { PureComponent } from 'react';
  3. import { getLocalizedDateFormatter } from '../../base/i18n';
  4. import { getAvatarURLByParticipantId } from '../../base/participants';
  5. /**
  6. * Formatter string to display the message timestamp.
  7. */
  8. const TIMESTAMP_FORMAT = 'H:mm';
  9. /**
  10. * The type of the React {@code Component} props of {@code AbstractChatMessage}.
  11. */
  12. export type Props = {
  13. /**
  14. * The URL of the avatar of the participant.
  15. */
  16. _avatarURL: string,
  17. /**
  18. * The representation of a chat message.
  19. */
  20. message: Object,
  21. /**
  22. * Whether or not the avatar image of the participant which sent the message
  23. * should be displayed.
  24. */
  25. showAvatar: boolean,
  26. /**
  27. * Whether or not the name of the participant which sent the message should
  28. * be displayed.
  29. */
  30. showDisplayName: boolean,
  31. /**
  32. * Whether or not the time at which the message was sent should be
  33. * displayed.
  34. */
  35. showTimestamp: boolean,
  36. /**
  37. * Invoked to receive translated strings.
  38. */
  39. t: Function
  40. };
  41. /**
  42. * Abstract component to display a chat message.
  43. */
  44. export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
  45. /**
  46. * Returns the timestamp to display for the message.
  47. *
  48. * @returns {string}
  49. */
  50. _getFormattedTimestamp() {
  51. return getLocalizedDateFormatter(new Date(this.props.message.timestamp))
  52. .format(TIMESTAMP_FORMAT);
  53. }
  54. }
  55. /**
  56. * Maps part of the Redux state to the props of this component.
  57. *
  58. * @param {Object} state - The Redux state.
  59. * @param {Props} ownProps - The own props of the component.
  60. * @returns {{
  61. * _avatarURL: string
  62. * }}
  63. */
  64. export function _mapStateToProps(state: Object, ownProps: Props) {
  65. const { message } = ownProps;
  66. return {
  67. _avatarURL: getAvatarURLByParticipantId(state, message.id)
  68. };
  69. }