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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // @flow
  2. import { PureComponent } from 'react';
  3. import { getAvatarURLByParticipantId } from '../../base/participants';
  4. /**
  5. * The type of the React {@code Component} props of {@code AbstractChatMessage}.
  6. */
  7. export type Props = {
  8. /**
  9. * The URL of the avatar of the participant.
  10. */
  11. _avatarURL: string,
  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. static defaultProps = {
  41. showAvatar: false,
  42. showDisplayName: false,
  43. showTimestamp: false
  44. };
  45. }
  46. /**
  47. * Maps part of the Redux state to the props of this component.
  48. *
  49. * @param {Object} state - The Redux state.
  50. * @param {Props} ownProps - The own props of the component.
  51. * @returns {{
  52. * _avatarURL: string
  53. * }}
  54. */
  55. export function _mapStateToProps(state: Object, ownProps: Props) {
  56. const { message } = ownProps;
  57. return {
  58. _avatarURL: getAvatarURLByParticipantId(state, message.id)
  59. };
  60. }