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.

AbstractMessageRecipient.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // @flow
  2. import { PureComponent } from 'react';
  3. import { getParticipantDisplayName, isLocalParticipantModerator } from '../../base/participants';
  4. import { setPrivateMessageRecipient } from '../actions';
  5. import { setLobbyChatActiveState } from '../actions.any';
  6. export type Props = {
  7. /**
  8. * Function used to translate i18n labels.
  9. */
  10. t: Function,
  11. /**
  12. * Function to remove the recipent setting of the chat window.
  13. */
  14. _onRemovePrivateMessageRecipient: Function,
  15. /**
  16. * Function to make the lobby message receipient inactive.
  17. */
  18. _onHideLobbyChatRecipient: Function,
  19. /**
  20. * The name of the message recipient, if any.
  21. */
  22. _privateMessageRecipient: ?string,
  23. /**
  24. * Is lobby messaging active.
  25. */
  26. _isLobbyChatActive: boolean,
  27. /**
  28. * The name of the lobby message recipient, if any.
  29. */
  30. _lobbyMessageRecipient: ?string,
  31. /**
  32. * Shows widget if it is necessary.
  33. */
  34. _visible: boolean;
  35. };
  36. /**
  37. * Abstract class for the {@code MessageRecipient} component.
  38. */
  39. export default class AbstractMessageRecipient<P: Props> extends PureComponent<P> {
  40. }
  41. /**
  42. * Maps part of the props of this component to Redux actions.
  43. *
  44. * @param {Function} dispatch - The Redux dispatch function.
  45. * @returns {Props}
  46. */
  47. export function _mapDispatchToProps(dispatch: Function): $Shape<Props> {
  48. return {
  49. _onRemovePrivateMessageRecipient: () => {
  50. dispatch(setPrivateMessageRecipient());
  51. },
  52. _onHideLobbyChatRecipient: () => {
  53. dispatch(setLobbyChatActiveState(false));
  54. }
  55. };
  56. }
  57. /**
  58. * Maps part of the Redux store to the props of this component.
  59. *
  60. * @param {Object} state - The Redux state.
  61. * @returns {Props}
  62. */
  63. export function _mapStateToProps(state: Object): $Shape<Props> {
  64. const { privateMessageRecipient, lobbyMessageRecipient, isLobbyChatActive } = state['features/chat'];
  65. return {
  66. _privateMessageRecipient:
  67. privateMessageRecipient ? getParticipantDisplayName(state, privateMessageRecipient.id) : undefined,
  68. _isLobbyChatActive: isLobbyChatActive,
  69. _lobbyMessageRecipient:
  70. isLobbyChatActive && lobbyMessageRecipient ? lobbyMessageRecipient.name : undefined,
  71. _visible: isLobbyChatActive ? isLocalParticipantModerator(state) : true
  72. };
  73. }