Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AbstractChatPrivacyDialog.tsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { PureComponent } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { IState, IStore } from '../../app/types';
  4. import { getParticipantById } from '../../base/participants/functions';
  5. import { Participant } from '../../base/participants/types';
  6. // eslint-disable-next-line lines-around-comment
  7. // @ts-ignore
  8. import { sendMessage, setPrivateMessageRecipient } from '../actions';
  9. interface Props extends WithTranslation {
  10. /**
  11. * Prop to be invoked on sending the message.
  12. */
  13. _onSendMessage: Function;
  14. /**
  15. * Prop to be invoked when the user wants to set a private recipient.
  16. */
  17. _onSetMessageRecipient: Function;
  18. /**
  19. * The participant retrieved from Redux by the participanrID prop.
  20. */
  21. _participant: Object;
  22. /**
  23. * The message that is about to be sent.
  24. */
  25. message: Object;
  26. /**
  27. * The ID of the participant that we think the message may be intended to.
  28. */
  29. participantID: string;
  30. }
  31. /**
  32. * Abstract class for the dialog displayed to avoid mis-sending private messages.
  33. */
  34. export class AbstractChatPrivacyDialog extends PureComponent<Props> {
  35. /**
  36. * Instantiates a new instance.
  37. *
  38. * @inheritdoc
  39. */
  40. constructor(props: Props) {
  41. super(props);
  42. this._onSendGroupMessage = this._onSendGroupMessage.bind(this);
  43. this._onSendPrivateMessage = this._onSendPrivateMessage.bind(this);
  44. }
  45. /**
  46. * Callback to be invoked for cancel action (user wants to send a group message).
  47. *
  48. * @returns {boolean}
  49. */
  50. _onSendGroupMessage() {
  51. this.props._onSendMessage(this.props.message);
  52. return true;
  53. }
  54. /**
  55. * Callback to be invoked for submit action (user wants to send a private message).
  56. *
  57. * @returns {void}
  58. */
  59. _onSendPrivateMessage() {
  60. const { message, _onSendMessage, _onSetMessageRecipient, _participant } = this.props;
  61. _onSetMessageRecipient(_participant);
  62. _onSendMessage(message);
  63. return true;
  64. }
  65. }
  66. /**
  67. * Maps part of the props of this component to Redux actions.
  68. *
  69. * @param {Function} dispatch - The Redux dispatch function.
  70. * @returns {Props}
  71. */
  72. export function _mapDispatchToProps(dispatch: IStore['dispatch']) {
  73. return {
  74. _onSendMessage: (message: Object) => {
  75. dispatch(sendMessage(message, true));
  76. },
  77. _onSetMessageRecipient: (participant: Participant) => {
  78. dispatch(setPrivateMessageRecipient(participant));
  79. }
  80. };
  81. }
  82. /**
  83. * Maps part of the Redux store to the props of this component.
  84. *
  85. * @param {IState} state - The Redux state.
  86. * @param {Props} ownProps - The own props of the component.
  87. * @returns {Props}
  88. */
  89. export function _mapStateToProps(state: IState, ownProps: Props) {
  90. return {
  91. _participant: getParticipantById(state, ownProps.participantID)
  92. };
  93. }