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

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-12-28 23:34:32 +00:00
import React, { Component } from 'react';
import Autolinker from 'autolinker';
2016-02-16 21:43:25 +00:00
import pure from 'pure-render-decorator';
2015-12-28 23:34:32 +00:00
import { timestamp } from '../util';
2016-02-16 21:43:25 +00:00
@pure
export default class Message extends Component {
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-02-16 21:43:25 +00:00
const content = Autolinker.link(message.message, { stripPrefix: false });
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`,
textIndent: `-${window.messageIndent}px`
};
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}
2016-02-16 21:43:25 +00:00
<span dangerouslySetInnerHTML={{ __html: ` ${content}` }}></span>
2015-12-28 23:34:32 +00:00
</p>
);
}
}