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

39 lines
941 B
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
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}>
<span className="message-time">{message.time}</span>{' '}
{message.from && (
<span
className="message-sender"
style={senderStyle}
onClick={() => onNickClick(message.from)}
>
{message.from}
</span>
)}
{` ${message.content}`}
</p>
);
};
2018-10-06 22:25:56 +00:00
export default memo(Message);