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

51 lines
1.1 KiB
JavaScript
Raw Normal View History

import React, { memo } from 'react';
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
const Message = ({ message, coloredNick, 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}>
2018-12-14 13:24:23 +00:00
{message.content}
<hr />
</div>
);
}
const style = {
paddingLeft: `${message.indent + 15}px`,
textIndent: `-${message.indent}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>
)}
2020-06-30 11:24:23 +00:00
<span>
{' '}
<Text coloredNick={coloredNick}>{message.content}</Text>
</span>
</p>
);
};
2018-10-06 22:25:56 +00:00
export default memo(Message);