Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. var MessagesInterfaceChatRoom = React.createClass({
  2. getInitialState: function() {
  3. return {
  4. chat_room: this.props.chat_room,
  5. current_user_id: this.props.current_user_id
  6. }
  7. },
  8.  
  9. componentWillReceiveProps (nextProps) {
  10. this.setState(nextProps)
  11. },
  12.  
  13. openChatRoom: function() {
  14. messageActions.index(this.props.chat_room.id)
  15. },
  16.  
  17. render: function() {
  18. if(this.state.chat_room.users.length == 2) {
  19. users = _.filter(this.state.chat_room.users, function(user) {
  20. return user.id != this.state.current_user_id
  21. }.bind(this))
  22.  
  23. user = _.first(users)
  24. header = user.nick
  25. }
  26.  
  27.  
  28. if(this.state.chat_room.users.length > 2) {
  29. header = '#Групповой чат'
  30. users = _.filter(this.state.chat_room.users, function(user) {
  31. return user.id != this.state.current_user_id
  32. }.bind(this))
  33. message = this.state.chat_room.message
  34. }
  35.  
  36. return (
  37. <div className="row">
  38. <div className="col-xs-12 message_row un_read" onClick={this.openChatRoom}>
  39. { this.state.chat_room.users.length == 2 ? <MessagesInterfaceChatRoomAvatarForOne user={user} /> : <MessagesInterfaceChatRoomAvatarForMany users={users} /> }
  40. <div className="right_side">
  41. <div className="header_wrap">
  42. <h6>{header}</h6>
  43. <span className="time">{this.state.chat_room.message.distance_of_time_in_words}</span>
  44. </div>
  45. <div className="message">
  46. { this.state.current_user_id == this.state.chat_room.message.sender_id ? <span className='you'>Вы:</span> : null }
  47. <span className='body'>{this.state.chat_room.message.message}</span>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. )
  53. }
  54. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement