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';
|
2018-10-07 23:34:53 +00:00
|
|
|
import stringToRGB from 'utils/color';
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
const Message = ({ message, coloredNick, style, onNickClick }) => {
|
|
|
|
const className = classnames('message', {
|
|
|
|
[`message-${message.type}`]: message.type
|
|
|
|
});
|
2017-05-06 21:02:45 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
style = {
|
|
|
|
...style,
|
|
|
|
paddingLeft: `${window.messageIndent + 15}px`,
|
|
|
|
textIndent: `-${window.messageIndent}px`
|
|
|
|
};
|
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>
|
|
|
|
)}
|
2018-11-05 06:11:15 +00:00
|
|
|
<span> {message.content}</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);
|