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

47 lines
1.1 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
import { timestamp, linkify } from '../util';
2015-12-28 23:34:32 +00:00
export default class Message extends PureComponent {
2015-12-28 23:34:32 +00:00
handleSenderClick = () => {
const { message, openPrivateChat, select } = this.props;
openPrivateChat(message.server, message.from);
select(message.server, message.from, true);
};
2015-12-28 23:34:32 +00:00
render() {
const { message } = this.props;
2016-01-05 18:29:22 +00:00
const classes = ['message'];
2015-12-28 23:34:32 +00:00
let sender = null;
2016-01-05 18:29:22 +00:00
if (message.type) {
classes.push(`message-${message.type}`);
}
2015-12-28 23:34:32 +00:00
if (message.from) {
sender = (
<span>
{' '}
<span className="message-sender" onClick={this.handleSenderClick}>
{message.from}
</span>
</span>
);
}
2016-02-16 21:43:25 +00:00
const style = {
paddingLeft: `${window.messageIndent + 15}px`,
2017-03-23 19:38:27 +00:00
textIndent: `-${window.messageIndent}px`,
...this.props.style
2016-02-16 21:43:25 +00:00
};
2015-12-28 23:34:32 +00:00
return (
2016-02-16 21:43:25 +00:00
<p className={classes.join(' ')} style={style}>
2015-12-28 23:34:32 +00:00
<span className="message-time">{timestamp(message.time)}</span>
{sender}
<span>{' '}{linkify(message.message)}</span>
2015-12-28 23:34:32 +00:00
</p>
);
}
}