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.

AbstractChatPrivacyDialog.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // @flow
  2. import { PureComponent } from 'react';
  3. import { getParticipantById } from '../../base/participants';
  4. import { sendMessage, setPrivateMessageRecipient } from '../actions';
  5. type Props = {
  6. /**
  7. * The message that is about to be sent.
  8. */
  9. message: Object,
  10. /**
  11. * The ID of the participant that we think the message may be intended to.
  12. */
  13. participantID: string,
  14. /**
  15. * Function to be used to translate i18n keys.
  16. */
  17. t: Function,
  18. /**
  19. * Prop to be invoked on sending the message.
  20. */
  21. _onSendMessage: Function,
  22. /**
  23. * Prop to be invoked when the user wants to set a private recipient.
  24. */
  25. _onSetMessageRecipient: Function,
  26. /**
  27. * The participant retrieved from Redux by the participanrID prop.
  28. */
  29. _participant: Object
  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. _onSendGroupMessage: () => boolean;
  46. /**
  47. * Callback to be invoked for cancel action (user wants to send a group message).
  48. *
  49. * @returns {boolean}
  50. */
  51. _onSendGroupMessage() {
  52. this.props._onSendMessage(this.props.message);
  53. return true;
  54. }
  55. _onSendPrivateMessage: () => boolean;
  56. /**
  57. * Callback to be invoked for submit action (user wants to send a private message).
  58. *
  59. * @returns {void}
  60. */
  61. _onSendPrivateMessage() {
  62. const { message, _onSendMessage, _onSetMessageRecipient, _participant } = this.props;
  63. _onSetMessageRecipient(_participant);
  64. _onSendMessage(message);
  65. return true;
  66. }
  67. }
  68. /**
  69. * Maps part of the props of this component to Redux actions.
  70. *
  71. * @param {Function} dispatch - The Redux dispatch function.
  72. * @returns {Props}
  73. */
  74. export function _mapDispatchToProps(dispatch: Function): $Shape<Props> {
  75. return {
  76. _onSendMessage: (message: Object) => {
  77. dispatch(sendMessage(message, true));
  78. },
  79. _onSetMessageRecipient: participant => {
  80. dispatch(setPrivateMessageRecipient(participant));
  81. }
  82. };
  83. }
  84. /**
  85. * Maps part of the Redux store to the props of this component.
  86. *
  87. * @param {Object} state - The Redux state.
  88. * @param {Props} ownProps - The own props of the component.
  89. * @returns {Props}
  90. */
  91. export function _mapStateToProps(state: Object, ownProps: Props): $Shape<Props> {
  92. return {
  93. _participant: getParticipantById(state, ownProps.participantID)
  94. };
  95. }