jiti-meet/react/features/chat/components/native/MessageRecipient.js

164 lines
4.5 KiB
JavaScript
Raw Normal View History

2019-10-07 12:35:04 +00:00
// @flow
import React from 'react';
import { Text, TouchableHighlight, View } from 'react-native';
2019-10-15 14:08:23 +00:00
import { ColorSchemeRegistry } from '../../../base/color-scheme';
2019-10-07 12:35:04 +00:00
import { translate } from '../../../base/i18n';
import { Icon, IconCloseCircle } from '../../../base/icons';
2019-10-07 12:35:04 +00:00
import { connect } from '../../../base/redux';
2019-10-15 14:08:23 +00:00
import { type StyleType } from '../../../base/styles';
import {
setParams
2022-01-25 12:55:57 +00:00
} from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
import { setLobbyChatActiveState, setPrivateMessageRecipient } from '../../actions.any';
2019-10-07 12:35:04 +00:00
import AbstractMessageRecipient, {
2019-10-15 14:08:23 +00:00
type Props as AbstractProps
2019-10-07 12:35:04 +00:00
} from '../AbstractMessageRecipient';
2019-10-15 14:08:23 +00:00
type Props = AbstractProps & {
/**
* The color-schemed stylesheet of the feature.
*/
_styles: StyleType,
/**
* The Redux dispatch function.
*/
dispatch: Function,
/**
* Is lobby messaging active.
*/
isLobbyChatActive: boolean,
/**
* The participant string for lobby chat messaging.
*/
lobbyMessageRecipient: Object,
/**
* The participant object set for private messaging.
*/
privateMessageRecipient: Object,
2019-10-15 14:08:23 +00:00
};
2019-10-07 12:35:04 +00:00
/**
* Class to implement the displaying of the recipient of the next message.
*/
2019-10-15 14:08:23 +00:00
class MessageRecipient extends AbstractMessageRecipient<Props> {
/**
* Constructor of the component.
*
* @param {Props} props - The props of the component.
*/
constructor(props: Props) {
super(props);
this._onResetPrivateMessageRecipient = this._onResetPrivateMessageRecipient.bind(this);
this._onResetLobbyMessageRecipient = this._onResetLobbyMessageRecipient.bind(this);
}
_onResetLobbyMessageRecipient: () => void;
/**
* Resets lobby message recipient from state.
*
* @returns {void}
*/
_onResetLobbyMessageRecipient() {
const { dispatch } = this.props;
dispatch(setLobbyChatActiveState(false));
}
_onResetPrivateMessageRecipient: () => void;
/**
* Resets private message recipient from state.
*
* @returns {void}
*/
_onResetPrivateMessageRecipient() {
const { dispatch } = this.props;
dispatch(setPrivateMessageRecipient());
setParams({
privateMessageRecipient: undefined
});
}
2019-10-07 12:35:04 +00:00
/**
* Implements {@code PureComponent#render}.
*
* @inheritdoc
* @returns {ReactElement}
2019-10-07 12:35:04 +00:00
*/
render() {
const { _styles, privateMessageRecipient, t,
isLobbyChatActive, lobbyMessageRecipient } = this.props;
if (isLobbyChatActive) {
return (
<View style = { _styles.lobbyMessageRecipientContainer }>
<Text style = { _styles.messageRecipientText }>
{ t('chat.lobbyChatMessageTo', {
recipient: lobbyMessageRecipient.name
}) }
</Text>
<TouchableHighlight
onPress = { this._onResetLobbyMessageRecipient }>
<Icon
src = { IconCloseCircle }
style = { _styles.messageRecipientCancelIcon } />
</TouchableHighlight>
</View>
);
}
2019-10-07 12:35:04 +00:00
if (!privateMessageRecipient) {
2019-10-07 12:35:04 +00:00
return null;
}
return (
2019-10-15 14:08:23 +00:00
<View style = { _styles.messageRecipientContainer }>
<Text style = { _styles.messageRecipientText }>
2019-10-07 12:35:04 +00:00
{ t('chat.messageTo', {
recipient: privateMessageRecipient.name
2019-10-07 12:35:04 +00:00
}) }
</Text>
<TouchableHighlight
onPress = { this._onResetPrivateMessageRecipient }
underlayColor = { 'transparent' }>
2019-10-07 12:35:04 +00:00
<Icon
src = { IconCloseCircle }
2019-10-15 14:08:23 +00:00
style = { _styles.messageRecipientCancelIcon } />
2019-10-07 12:35:04 +00:00
</TouchableHighlight>
</View>
);
}
}
2019-10-15 14:08:23 +00:00
/**
* Maps part of the redux state to the props of this component.
*
* @param {Object} state - The Redux state.
* @returns {Props}
*/
function _mapStateToProps(state) {
const { lobbyMessageRecipient, isLobbyChatActive } = state['features/chat'];
2019-10-15 14:08:23 +00:00
return {
_styles: ColorSchemeRegistry.get(state, 'Chat'),
isLobbyChatActive,
lobbyMessageRecipient
2019-10-15 14:08:23 +00:00
};
}
export default translate(connect(_mapStateToProps)(MessageRecipient));