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.ts 2.4KB

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