"use strict";
var Chatroom = React.createClass({
getDefaultProps() {
return {
history: []
};
},
componentDidMount() {
let self = this;
socket.on("message:append", data => {
let history = self.props.history;
history.push(data);
self.setProps({
history: history.sort((a, b) => {
return new Date(a.createdAt) - new Date(b.createdAt);
})
});
self.scrollToBottom();
});
// Message History Retrieved
socket.on("message:refresh", data => {
self.setProps({
history: data.chatHistory
});
self.scrollToBottom();
});
socket.on("users:update", data => {
self.setProps({
currentUser: data.currentUser
});
});
socket.emit("message:refresh", {});
},
sendMessage(message) {
socket.emit("newMessage", {message: message});
},
scrollToBottom() {
let node = React.findDOMNode(this.refs.messageContainer);
node.scrollTop = node.scrollHeight;
},
render() {
let messages = this.props.history.map(message =>
{this.props.message.content}