-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversation_item.jsx
68 lines (51 loc) · 1.89 KB
/
conversation_item.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React from 'react';
import { Link } from 'react-router';
import TimeAgo from 'react-timeago';
import emoji from 'react-easy-emoji';
class ConversationItem extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
this.otherUser = this.props.currentUser.id ===
this.props.conversation.sender.id ?
this.props.conversation.recipient : this.props.conversation.sender;
}
handleClick() {
this.props.openChat( {[this.props.conversation.id] :
{conversation: this.props.conversation, otherUser: this.otherUser}});
this.props.toggleChat();
}
render() {
let messageUnread =
this.props.conversation.message.read ? "msg-read" : "msg-unread";
if (this.props.conversation.message.user_id === this.props.currentUser.id)
messageUnread = "msg-read";
return (
<div className={messageUnread}>
<li onClick={this.handleClick}>
<div className="conversation-item">
<div className="conversation-circle-picture">
<img src={this.otherUser.profile_url} />
</div>
<div className="conversation-content-center">
<div className="conversation-content">
<div className="conversation-content-header">
<div className="conversation-content-name">
{`${this.otherUser.fname} ${this.otherUser.lname}`}
</div>
<div className="conversation-content-time">
<TimeAgo date={this.props.conversation.time}/>
</div>
</div>
<div className="conversation-content-message">
{emoji(this.props.conversation.message.body)}
</div>
</div>
</div>
</div>
</li>
</div>
);
}
}
export default ConversationItem;