Files
jitsi-meet/react/features/chat/components/native/PrivateMessageButton.tsx

111 lines
3.5 KiB
TypeScript
Raw Normal View History

import { connect } from 'react-redux';
import { IReduxState } from '../../../app/types';
2023-03-31 14:04:33 +03:00
import { CHAT_ENABLED } from '../../../base/flags/constants';
import { getFeatureFlag } from '../../../base/flags/functions';
import { translate } from '../../../base/i18n/functions';
import { IconMessage, IconReply } from '../../../base/icons/svg';
import { getParticipantById } from '../../../base/participants/functions';
import { IParticipant } from '../../../base/participants/types';
import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
2024-02-02 12:08:01 -06:00
import { arePollsDisabled } from '../../../conference/functions.any';
2022-01-25 14:55:57 +02:00
import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
import { screen } from '../../../mobile/navigation/routes';
import { handleLobbyChatInitialized, openChat } from '../../actions.native';
2019-10-07 14:35:04 +02:00
export interface IProps extends AbstractButtonProps {
2019-10-07 14:35:04 +02:00
/**
* True if message is a lobby chat message.
2019-10-07 14:35:04 +02:00
*/
_isLobbyMessage: boolean;
2019-10-07 14:35:04 +02:00
/**
* True if the polls feature is disabled.
2019-10-07 14:35:04 +02:00
*/
_isPollsDisabled?: boolean;
2019-10-07 14:35:04 +02:00
/**
* The participant object retrieved from Redux.
*/
_participant?: IParticipant;
/**
* The ID of the participant that the message is to be sent.
*/
participantID: string;
2019-10-07 14:35:04 +02:00
/**
* True if the button is rendered as a reply button.
2019-10-07 14:35:04 +02:00
*/
reply: boolean;
}
2019-10-07 14:35:04 +02:00
/**
* Class to render a button that initiates the sending of a private message through chat.
2019-10-07 14:35:04 +02:00
*/
class PrivateMessageButton extends AbstractButton<IProps, any> {
override accessibilityLabel = 'toolbar.accessibilityLabel.privateMessage';
override icon = IconMessage;
override label = 'toolbar.privateMessage';
override toggledIcon = IconReply;
2019-10-07 14:35:04 +02:00
/**
* Handles clicking / pressing the button.
2019-10-07 14:35:04 +02:00
*
* @private
* @returns {void}
*/
override _handleClick() {
if (this.props._isLobbyMessage) {
this.props.dispatch(handleLobbyChatInitialized(this.props.participantID));
}
this.props.dispatch(openChat(this.props._participant));
this.props._isPollsDisabled
? navigate(screen.conference.chat, {
privateMessageRecipient: this.props._participant
})
: navigate(screen.conference.chatandpolls.main, {
screen: screen.conference.chatandpolls.tab.chat,
params: {
privateMessageRecipient: this.props._participant
}
});
2019-10-07 14:35:04 +02: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}
*/
override _isToggled() {
2019-10-07 14:35:04 +02:00
return this.props.reply;
}
}
/**
* Maps part of the Redux store to the props of this component.
*
* @param {Object} state - The Redux state.
* @param {IProps} ownProps - The own props of the component.
* @returns {IProps}
2019-10-07 14:35:04 +02:00
*/
export function _mapStateToProps(state: IReduxState, ownProps: any) {
const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
const { visible = enabled, isLobbyMessage, participantID } = ownProps;
2019-10-07 14:35:04 +02:00
return {
2024-02-02 12:08:01 -06:00
_isPollsDisabled: arePollsDisabled(state),
_participant: getParticipantById(state, participantID),
_isLobbyMessage: isLobbyMessage,
visible
2019-10-07 14:35:04 +02:00
};
}
export default translate(connect(_mapStateToProps)(PrivateMessageButton));