2018-11-04 06:22:46 +00:00
|
|
|
import React, { memo } from 'react';
|
2018-06-03 04:18:03 +00:00
|
|
|
import classnames from 'classnames';
|
2020-06-30 11:24:23 +00:00
|
|
|
import Text from 'components/Text';
|
2018-10-07 23:34:53 +00:00
|
|
|
import stringToRGB from 'utils/color';
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2020-06-03 01:04:38 +00:00
|
|
|
const Message = ({ message, coloredNick, onNickClick }) => {
|
2018-11-04 06:22:46 +00:00
|
|
|
const className = classnames('message', {
|
|
|
|
[`message-${message.type}`]: message.type
|
|
|
|
});
|
2017-05-06 21:02:45 +00:00
|
|
|
|
2018-12-14 13:24:23 +00:00
|
|
|
if (message.type === 'date') {
|
|
|
|
return (
|
2020-06-03 01:04:38 +00:00
|
|
|
<div className={className}>
|
2018-12-14 13:24:23 +00:00
|
|
|
{message.content}
|
|
|
|
<hr />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-03 01:04:38 +00:00
|
|
|
const style = {
|
|
|
|
paddingLeft: `${message.indent + 15}px`,
|
|
|
|
textIndent: `-${message.indent}px`
|
2018-11-04 06:22:46 +00:00
|
|
|
};
|
2018-06-03 04:18:03 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
const senderStyle = {};
|
|
|
|
if (message.from && coloredNick) {
|
|
|
|
senderStyle.color = stringToRGB(message.from);
|
|
|
|
}
|
2016-02-16 21:43:25 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
return (
|
|
|
|
<p className={className} style={style}>
|
2018-11-05 06:11:15 +00:00
|
|
|
<span className="message-time">{message.time} </span>
|
2018-11-04 06:22:46 +00:00
|
|
|
{message.from && (
|
|
|
|
<span
|
|
|
|
className="message-sender"
|
|
|
|
style={senderStyle}
|
|
|
|
onClick={() => onNickClick(message.from)}
|
|
|
|
>
|
|
|
|
{message.from}
|
|
|
|
</span>
|
|
|
|
)}
|
2020-06-30 11:24:23 +00:00
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
<Text coloredNick={coloredNick}>{message.content}</Text>
|
|
|
|
</span>
|
2018-11-04 06:22:46 +00:00
|
|
|
</p>
|
|
|
|
);
|
|
|
|
};
|
2018-10-06 22:25:56 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
export default memo(Message);
|