jiti-meet/react/features/chat/components/AbstractChatPrivacyDialog.tsx

111 lines
2.8 KiB
TypeScript
Raw Normal View History

2019-10-07 12:35:04 +00:00
import { PureComponent } from 'react';
import { WithTranslation } from 'react-i18next';
2019-10-07 12:35:04 +00:00
import { IState, IStore } from '../../app/types';
import { getParticipantById } from '../../base/participants/functions';
import { Participant } from '../../base/participants/types';
// eslint-disable-next-line lines-around-comment
// @ts-ignore
2020-05-20 10:57:03 +00:00
import { sendMessage, setPrivateMessageRecipient } from '../actions';
2019-10-07 12:35:04 +00:00
interface Props extends WithTranslation {
2019-10-07 12:35:04 +00:00
/**
* Prop to be invoked on sending the message.
2019-10-07 12:35:04 +00:00
*/
_onSendMessage: Function;
2019-10-07 12:35:04 +00:00
/**
* Prop to be invoked when the user wants to set a private recipient.
2019-10-07 12:35:04 +00:00
*/
_onSetMessageRecipient: Function;
2019-10-07 12:35:04 +00:00
/**
* The participant retrieved from Redux by the participanrID prop.
2019-10-07 12:35:04 +00:00
*/
_participant: Object;
2019-10-07 12:35:04 +00:00
/**
* The message that is about to be sent.
2019-10-07 12:35:04 +00:00
*/
message: Object;
2019-10-07 12:35:04 +00:00
/**
* The ID of the participant that we think the message may be intended to.
2019-10-07 12:35:04 +00:00
*/
participantID: string;
}
2019-10-07 12:35:04 +00:00
/**
* Abstract class for the dialog displayed to avoid mis-sending private messages.
*/
export class AbstractChatPrivacyDialog extends PureComponent<Props> {
/**
* Instantiates a new instance.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
this._onSendGroupMessage = this._onSendGroupMessage.bind(this);
this._onSendPrivateMessage = this._onSendPrivateMessage.bind(this);
}
/**
* Callback to be invoked for cancel action (user wants to send a group message).
*
* @returns {boolean}
*/
_onSendGroupMessage() {
this.props._onSendMessage(this.props.message);
return true;
}
/**
* Callback to be invoked for submit action (user wants to send a private message).
*
* @returns {void}
*/
_onSendPrivateMessage() {
const { message, _onSendMessage, _onSetMessageRecipient, _participant } = this.props;
_onSetMessageRecipient(_participant);
_onSendMessage(message);
return true;
}
}
/**
* Maps part of the props of this component to Redux actions.
*
* @param {Function} dispatch - The Redux dispatch function.
* @returns {Props}
*/
export function _mapDispatchToProps(dispatch: IStore['dispatch']) {
2019-10-07 12:35:04 +00:00
return {
_onSendMessage: (message: Object) => {
dispatch(sendMessage(message, true));
},
_onSetMessageRecipient: (participant: Participant) => {
2019-10-07 12:35:04 +00:00
dispatch(setPrivateMessageRecipient(participant));
}
};
}
/**
* Maps part of the Redux store to the props of this component.
*
* @param {IState} state - The Redux state.
2019-10-07 12:35:04 +00:00
* @param {Props} ownProps - The own props of the component.
* @returns {Props}
*/
export function _mapStateToProps(state: IState, ownProps: Props) {
2019-10-07 12:35:04 +00:00
return {
_participant: getParticipantById(state, ownProps.participantID)
};
}