jiti-meet/react/features/chat/components/AbstractMessageRecipient.js

89 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-10-07 12:35:04 +00:00
// @flow
import { PureComponent } from 'react';
import { getParticipantDisplayName, isLocalParticipantModerator } from '../../base/participants';
2019-10-07 12:35:04 +00:00
import { setPrivateMessageRecipient } from '../actions';
import { setLobbyChatActiveState } from '../actions.any';
2019-10-07 12:35:04 +00:00
2019-10-15 14:08:23 +00:00
export type Props = {
2019-10-07 12:35:04 +00:00
/**
* Function used to translate i18n labels.
*/
t: Function,
/**
* Function to remove the recipent setting of the chat window.
*/
_onRemovePrivateMessageRecipient: Function,
/**
* Function to make the lobby message recipient inactive.
*/
_onHideLobbyChatRecipient: Function,
2019-10-07 12:35:04 +00:00
/**
* The name of the message recipient, if any.
*/
_privateMessageRecipient: ?string,
/**
* Is lobby messaging active.
*/
_isLobbyChatActive: boolean,
/**
* The name of the lobby message recipient, if any.
*/
_lobbyMessageRecipient: ?string,
/**
* Shows widget if it is necessary.
*/
_visible: boolean;
2019-10-07 12:35:04 +00:00
};
/**
* Abstract class for the {@code MessageRecipient} component.
*/
2019-10-15 14:08:23 +00:00
export default class AbstractMessageRecipient<P: Props> extends PureComponent<P> {
2019-10-07 12:35:04 +00:00
}
/**
* Maps part of the props of this component to Redux actions.
*
* @param {Function} dispatch - The Redux dispatch function.
* @returns {Props}
*/
export function _mapDispatchToProps(dispatch: Function): $Shape<Props> {
return {
_onRemovePrivateMessageRecipient: () => {
dispatch(setPrivateMessageRecipient());
},
_onHideLobbyChatRecipient: () => {
dispatch(setLobbyChatActiveState(false));
2019-10-07 12:35:04 +00:00
}
};
}
/**
* Maps part of the Redux store to the props of this component.
*
* @param {Object} state - The Redux state.
* @returns {Props}
*/
export function _mapStateToProps(state: Object): $Shape<Props> {
const { privateMessageRecipient, lobbyMessageRecipient, isLobbyChatActive } = state['features/chat'];
2019-10-07 12:35:04 +00:00
return {
_privateMessageRecipient:
privateMessageRecipient ? getParticipantDisplayName(state, privateMessageRecipient.id) : undefined,
_isLobbyChatActive: isLobbyChatActive,
_lobbyMessageRecipient:
isLobbyChatActive && lobbyMessageRecipient ? lobbyMessageRecipient.name : undefined,
_visible: isLobbyChatActive ? isLocalParticipantModerator(state) : true
2019-10-07 12:35:04 +00:00
};
}