2018-08-29 17:24:25 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
import React from 'react';
|
2018-08-29 17:24:25 +00:00
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2021-12-17 12:39:15 +00:00
|
|
|
import Message from '../../../base/react/components/web/Message';
|
2022-03-03 17:29:38 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2019-10-15 14:08:23 +00:00
|
|
|
import { MESSAGE_TYPE_LOCAL } from '../../constants';
|
2021-11-11 12:32:01 +00:00
|
|
|
import AbstractChatMessage, { type Props } from '../AbstractChatMessage';
|
|
|
|
|
|
|
|
import PrivateMessageButton from './PrivateMessageButton';
|
2018-08-29 17:24:25 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-13 19:34:38 +00:00
|
|
|
* Renders a single chat message.
|
2018-08-29 17:24:25 +00:00
|
|
|
*/
|
2019-01-13 19:34:38 +00:00
|
|
|
class ChatMessage extends AbstractChatMessage<Props> {
|
2018-08-29 17:24:25 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2022-03-03 17:29:38 +00:00
|
|
|
const { message, t, knocking } = this.props;
|
2018-08-29 17:24:25 +00:00
|
|
|
|
|
|
|
return (
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
|
|
|
className = 'chatmessage-wrapper'
|
2022-08-26 06:21:41 +00:00
|
|
|
id = { this.props.message.messageId }
|
2021-06-10 12:48:44 +00:00
|
|
|
tabIndex = { -1 }>
|
2022-03-03 17:29:38 +00:00
|
|
|
<div
|
|
|
|
className = { `chatmessage ${message.privateMessage ? 'privatemessage' : ''} ${
|
|
|
|
message.lobbyChat && !knocking ? 'lobbymessage' : ''}` }>
|
2019-10-22 07:56:42 +00:00
|
|
|
<div className = 'replywrapper'>
|
|
|
|
<div className = 'messagecontent'>
|
|
|
|
{ this.props.showDisplayName && this._renderDisplayName() }
|
|
|
|
<div className = 'usermessage'>
|
2021-06-10 12:48:44 +00:00
|
|
|
<span className = 'sr-only'>
|
|
|
|
{ this.props.message.displayName === this.props.message.recipient
|
|
|
|
? t('chat.messageAccessibleTitleMe')
|
|
|
|
: t('chat.messageAccessibleTitle',
|
|
|
|
{ user: this.props.message.displayName }) }
|
|
|
|
</span>
|
2021-12-17 12:39:15 +00:00
|
|
|
<Message text = { this._getMessageText() } />
|
2019-10-22 07:56:42 +00:00
|
|
|
</div>
|
2022-03-03 17:29:38 +00:00
|
|
|
{ (message.privateMessage || (message.lobbyChat && !knocking))
|
|
|
|
&& this._renderPrivateNotice() }
|
2019-10-07 12:35:04 +00:00
|
|
|
</div>
|
2022-03-03 17:29:38 +00:00
|
|
|
{ (message.privateMessage || (message.lobbyChat && !knocking))
|
|
|
|
&& message.messageType !== MESSAGE_TYPE_LOCAL
|
2019-10-22 07:56:42 +00:00
|
|
|
&& (
|
2022-03-03 17:29:38 +00:00
|
|
|
<div
|
|
|
|
className = { `messageactions ${
|
|
|
|
message.lobbyChat ? 'lobbychatmessageactions' : ''}` }>
|
2019-10-22 07:56:42 +00:00
|
|
|
<PrivateMessageButton
|
2022-03-03 17:29:38 +00:00
|
|
|
isLobbyMessage = { message.lobbyChat }
|
2019-10-22 07:56:42 +00:00
|
|
|
participantID = { message.id }
|
|
|
|
reply = { true }
|
|
|
|
showLabel = { false } />
|
|
|
|
</div>
|
|
|
|
) }
|
2019-05-06 19:30:38 +00:00
|
|
|
</div>
|
2018-12-03 18:01:40 +00:00
|
|
|
</div>
|
2019-05-06 19:30:38 +00:00
|
|
|
{ this.props.showTimestamp && this._renderTimestamp() }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getFormattedTimestamp: () => string;
|
|
|
|
|
2019-10-09 08:34:01 +00:00
|
|
|
_getMessageText: () => string;
|
|
|
|
|
2019-10-07 12:35:04 +00:00
|
|
|
_getPrivateNoticeMessage: () => string;
|
|
|
|
|
2019-05-06 19:30:38 +00:00
|
|
|
/**
|
|
|
|
* Renders the display name of the sender.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<*>}
|
|
|
|
*/
|
|
|
|
_renderDisplayName() {
|
|
|
|
return (
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
|
|
|
aria-hidden = { true }
|
|
|
|
className = 'display-name'>
|
2019-05-06 19:30:38 +00:00
|
|
|
{ this.props.message.displayName }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-07 12:35:04 +00:00
|
|
|
/**
|
|
|
|
* Renders the message privacy notice.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<*>}
|
|
|
|
*/
|
|
|
|
_renderPrivateNotice() {
|
|
|
|
return (
|
|
|
|
<div className = 'privatemessagenotice'>
|
|
|
|
{ this._getPrivateNoticeMessage() }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-06 19:30:38 +00:00
|
|
|
/**
|
|
|
|
* Renders the time at which the message was sent.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<*>}
|
|
|
|
*/
|
|
|
|
_renderTimestamp() {
|
|
|
|
return (
|
|
|
|
<div className = 'timestamp'>
|
|
|
|
{ this._getFormattedTimestamp() }
|
2018-08-29 17:24:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 17:29:38 +00:00
|
|
|
/**
|
|
|
|
* Maps part of the Redux store to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state: Object): $Shape<Props> {
|
|
|
|
const { knocking } = state['features/lobby'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
knocking
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(ChatMessage));
|