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

109 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 { IReduxState, IStore } from '../../app/types';
import { getParticipantById } from '../../base/participants/functions';
import { IParticipant } from '../../base/participants/types';
2020-05-20 10:57:03 +00:00
import { sendMessage, setPrivateMessageRecipient } from '../actions';
2019-10-07 12:35:04 +00:00
interface IProps 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<IProps> {
2019-10-07 12:35:04 +00:00
/**
* Instantiates a new instance.
*
* @inheritdoc
*/
constructor(props: IProps) {
2019-10-07 12:35:04 +00:00
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 {IProps}
2019-10-07 12:35:04 +00:00
*/
export function _mapDispatchToProps(dispatch: IStore['dispatch']) {
2019-10-07 12:35:04 +00:00
return {
_onSendMessage: (message: string) => {
2019-10-07 12:35:04 +00:00
dispatch(sendMessage(message, true));
},
_onSetMessageRecipient: (participant: IParticipant) => {
2019-10-07 12:35:04 +00:00
dispatch(setPrivateMessageRecipient(participant));
}
};
}
/**
* Maps part of the Redux store to the props of this component.
*
* @param {IReduxState} state - The Redux state.
* @param {IProps} ownProps - The own props of the component.
* @returns {IProps}
2019-10-07 12:35:04 +00:00
*/
export function _mapStateToProps(state: IReduxState, ownProps: IProps) {
2019-10-07 12:35:04 +00:00
return {
_participant: getParticipantById(state, ownProps.participantID)
};
}