2016-12-21 08:56:29 +00:00
|
|
|
import React from 'react'
|
|
|
|
import Autolinker from 'autolinker'
|
2017-01-09 18:14:20 +00:00
|
|
|
import Util from '../../Metamaps/Util'
|
2016-12-21 08:56:29 +00:00
|
|
|
|
|
|
|
const linker = new Autolinker({ newWindow: true, truncate: 50, email: false, phone: false })
|
|
|
|
|
|
|
|
function addZero(i) {
|
|
|
|
if (i < 10) {
|
|
|
|
i = '0' + i
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatDate(created_at) {
|
|
|
|
let date = new Date(created_at)
|
|
|
|
let formatted = (date.getMonth() + 1) + '/' + date.getDate()
|
|
|
|
formatted += ' ' + addZero(date.getHours()) + ':' + addZero(date.getMinutes())
|
|
|
|
return formatted
|
|
|
|
}
|
|
|
|
|
|
|
|
const Message = props => {
|
2017-01-04 23:11:44 +00:00
|
|
|
const { user_image, user_name, message, created_at, heading } = props
|
2017-01-09 18:14:20 +00:00
|
|
|
const messageHtml = {__html: linker.link(Util.addEmoji(message, { emoticons: false }))}
|
|
|
|
|
2016-12-21 08:56:29 +00:00
|
|
|
return (
|
|
|
|
<div className="chat-message">
|
|
|
|
<div className="chat-message-user">
|
2017-01-04 23:11:44 +00:00
|
|
|
{heading && <img src={user_image} />}
|
2016-12-21 08:56:29 +00:00
|
|
|
</div>
|
2017-01-04 23:11:44 +00:00
|
|
|
{heading && <div className="chat-message-meta">
|
|
|
|
<span className='chat-message-username'>{user_name}</span>
|
|
|
|
<span className='chat-message-time'>{formatDate(created_at)}</span>
|
|
|
|
</div>}
|
2016-12-21 08:56:29 +00:00
|
|
|
<div className="chat-message-text" dangerouslySetInnerHTML={messageHtml}></div>
|
|
|
|
<div className="clearfloat"></div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Message
|