選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AbstractChatPrivacyDialog.tsx 2.8KB

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