2019-01-13 19:34:38 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-04-29 07:35:18 +00:00
|
|
|
import { CHAT_ENABLED, getFeatureFlag } from '../../../base/flags';
|
2022-06-07 14:37:54 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2022-11-08 10:24:32 +00:00
|
|
|
import { IconChatUnread, IconMessage } from '../../../base/icons';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2019-01-13 19:34:38 +00:00
|
|
|
import {
|
|
|
|
AbstractButton,
|
|
|
|
type AbstractButtonProps
|
2020-07-24 12:14:33 +00:00
|
|
|
} from '../../../base/toolbox/components';
|
2022-01-25 12:55:57 +00:00
|
|
|
import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
|
|
|
|
import { screen } from '../../../mobile/navigation/routes';
|
2019-01-13 19:34:38 +00:00
|
|
|
import { getUnreadCount } from '../../functions';
|
|
|
|
|
2021-10-20 19:29:21 +00:00
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
|
|
|
/**
|
2021-10-20 19:29:21 +00:00
|
|
|
* True if the polls feature is disabled.
|
2019-01-13 19:34:38 +00:00
|
|
|
*/
|
2021-10-20 19:29:21 +00:00
|
|
|
_isPollsDisabled: boolean,
|
2021-02-12 11:18:16 +00:00
|
|
|
|
2021-10-20 19:29:21 +00:00
|
|
|
/**
|
|
|
|
* The unread message count.
|
|
|
|
*/
|
|
|
|
_unreadMessageCount: number
|
2019-01-13 19:34:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements an {@link AbstractButton} to open the chat screen on mobile.
|
|
|
|
*/
|
|
|
|
class ChatButton extends AbstractButton<Props, *> {
|
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.chat';
|
2022-11-08 10:24:32 +00:00
|
|
|
icon = IconMessage;
|
2019-01-13 19:34:38 +00:00
|
|
|
label = 'toolbar.chat';
|
2019-08-30 16:39:06 +00:00
|
|
|
toggledIcon = IconChatUnread;
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button, and opens the appropriate dialog.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_handleClick() {
|
2021-10-20 19:29:21 +00:00
|
|
|
this.props._isPollsDisabled
|
|
|
|
? navigate(screen.conference.chat)
|
|
|
|
: navigate(screen.conference.chatandpolls.main);
|
2019-01-13 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the button toggled when there are unread messages.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isToggled() {
|
|
|
|
return Boolean(this.props._unreadMessageCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the redux state to the component's props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
2020-04-29 07:35:18 +00:00
|
|
|
* @param {Object} ownProps - The properties explicitly passed to the component instance.
|
|
|
|
* @returns {Props}
|
2019-01-13 19:34:38 +00:00
|
|
|
*/
|
2020-04-29 07:35:18 +00:00
|
|
|
function _mapStateToProps(state, ownProps) {
|
|
|
|
const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
|
2021-10-20 19:29:21 +00:00
|
|
|
const { disablePolls } = state['features/base/config'];
|
2020-04-29 07:35:18 +00:00
|
|
|
const { visible = enabled } = ownProps;
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
return {
|
2021-10-20 19:29:21 +00:00
|
|
|
_isPollsDisabled: disablePolls,
|
2020-04-29 07:35:18 +00:00
|
|
|
_unreadMessageCount: getUnreadCount(state),
|
|
|
|
visible
|
2019-01-13 19:34:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-07 14:37:54 +00:00
|
|
|
export default translate(connect(_mapStateToProps)(ChatButton));
|