Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MessagesInterfaceChatRoom = React.createClass({
- getInitialState: function() {
- return {
- chat_room: this.props.chat_room,
- current_user_id: this.props.current_user_id
- }
- },
- componentWillReceiveProps (nextProps) {
- this.setState(nextProps)
- },
- openChatRoom: function() {
- messageActions.index(this.props.chat_room.id)
- },
- render: function() {
- if(this.state.chat_room.users.length == 2) {
- users = _.filter(this.state.chat_room.users, function(user) {
- return user.id != this.state.current_user_id
- }.bind(this))
- user = _.first(users)
- header = user.nick
- }
- if(this.state.chat_room.users.length > 2) {
- header = '#Групповой чат'
- users = _.filter(this.state.chat_room.users, function(user) {
- return user.id != this.state.current_user_id
- }.bind(this))
- message = this.state.chat_room.message
- }
- return (
- <div className="row">
- <div className="col-xs-12 message_row un_read" onClick={this.openChatRoom}>
- { this.state.chat_room.users.length == 2 ? <MessagesInterfaceChatRoomAvatarForOne user={user} /> : <MessagesInterfaceChatRoomAvatarForMany users={users} /> }
- <div className="right_side">
- <div className="header_wrap">
- <h6>{header}</h6>
- <span className="time">{this.state.chat_room.message.distance_of_time_in_words}</span>
- </div>
- <div className="message">
- { this.state.current_user_id == this.state.chat_room.message.sender_id ? <span className='you'>Вы:</span> : null }
- <span className='body'>{this.state.chat_room.message.message}</span>
- </div>
- </div>
- </div>
- </div>
- )
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement