2019-10-07 12:35:04 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-11-11 12:32:01 +00:00
|
|
|
import { CHAT_ENABLED, getFeatureFlag } from '../../../base/flags';
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { IconMessage, IconReply } from '../../../base/icons';
|
|
|
|
import { getParticipantById } from '../../../base/participants';
|
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
|
2022-03-03 17:29:38 +00:00
|
|
|
import { openChat, handleLobbyChatInitialized } from '../../actions';
|
2019-10-07 12:35:04 +00:00
|
|
|
|
|
|
|
export type Props = AbstractButtonProps & {
|
|
|
|
|
2022-03-03 17:29:38 +00:00
|
|
|
/**
|
|
|
|
* True if the message is a lobby chat message.
|
|
|
|
*/
|
|
|
|
isLobbyMessage: boolean,
|
|
|
|
|
2019-10-07 12:35:04 +00:00
|
|
|
/**
|
|
|
|
* The ID of the participant that the message is to be sent.
|
|
|
|
*/
|
|
|
|
participantID: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the button is rendered as a reply button.
|
|
|
|
*/
|
|
|
|
reply: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to be used to translate i18n labels.
|
|
|
|
*/
|
|
|
|
t: Function,
|
|
|
|
|
|
|
|
/**
|
2021-02-12 11:18:16 +00:00
|
|
|
* The Redux dispatch function.
|
2019-10-07 12:35:04 +00:00
|
|
|
*/
|
2021-02-12 11:18:16 +00:00
|
|
|
dispatch: Function,
|
2019-10-07 12:35:04 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-16 15:59:33 +00:00
|
|
|
* The participant object retrieved from Redux.
|
2019-10-07 12:35:04 +00:00
|
|
|
*/
|
2021-02-12 11:18:16 +00:00
|
|
|
_participant: Object,
|
2019-10-07 12:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to render a button that initiates the sending of a private message through chet.
|
|
|
|
*/
|
|
|
|
class PrivateMessageButton extends AbstractButton<Props, any> {
|
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.privateMessage';
|
|
|
|
icon = IconMessage;
|
|
|
|
label = 'toolbar.privateMessage';
|
|
|
|
toggledIcon = IconReply;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button, and kicks the participant.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_handleClick() {
|
2022-03-03 17:29:38 +00:00
|
|
|
const { _participant, participantID, dispatch, isLobbyMessage } = this.props;
|
2021-11-11 12:32:01 +00:00
|
|
|
|
2022-03-03 17:29:38 +00:00
|
|
|
if (isLobbyMessage) {
|
|
|
|
dispatch(handleLobbyChatInitialized(participantID));
|
|
|
|
} else {
|
|
|
|
dispatch(openChat(_participant));
|
|
|
|
}
|
2019-10-07 12:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to be implemented by subclasses, which must return a
|
|
|
|
* {@code boolean} value indicating if this button is toggled or not.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isToggled() {
|
|
|
|
return this.props.reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the Redux store to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @param {Props} ownProps - The own props of the component.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
export function _mapStateToProps(state: Object, ownProps: Props): $Shape<Props> {
|
2021-03-12 07:34:31 +00:00
|
|
|
const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
|
|
|
|
const { visible = enabled } = ownProps;
|
|
|
|
|
2019-10-07 12:35:04 +00:00
|
|
|
return {
|
2021-03-12 07:34:31 +00:00
|
|
|
_participant: getParticipantById(state, ownProps.participantID),
|
|
|
|
visible
|
2019-10-07 12:35:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-12 11:18:16 +00:00
|
|
|
export default translate(connect(_mapStateToProps)(PrivateMessageButton));
|