dispatch/client/js/components/pages/Chat/Message.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

import React, { memo } from 'react';
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
const Message = ({ message, coloredNick, style, onNickClick }) => {
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 (
<div className={className} style={style}>
{message.content}
<hr />
</div>
);
}
style = {
...style,
paddingLeft: `${window.messageIndent + 15}px`,
textIndent: `-${window.messageIndent}px`
};
const senderStyle = {};
if (message.from && coloredNick) {
senderStyle.color = stringToRGB(message.from);
}
2016-02-16 21:43:25 +00:00
return (
<p className={className} style={style}>
2018-11-05 06:11:15 +00:00
<span className="message-time">{message.time} </span>
{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>
</p>
);
};
2018-10-06 22:25:56 +00:00
export default memo(Message);