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