New message append method

This commit is contained in:
Chris Blanchard 2015-09-14 22:10:26 +01:00
parent 58417c9a90
commit 41d2f4417e
2 changed files with 6 additions and 4 deletions

View file

@ -4,7 +4,7 @@
* Chatroom Controller
*
* Server API
* message:new - New message needs to be displayed
* message:append - New message to be added to history
* message:refresh - Reload all messages
*
* Client API
@ -20,7 +20,7 @@ var Message = mongoose.model("Message");
module.exports = namespace => {
var broadcastUpdate = message => {
namespace.emit("message:new", message);
namespace.emit("message:append", message);
};
var refreshMessages = socket => {

View file

@ -10,11 +10,13 @@ var Chatroom = React.createClass({
componentDidMount() {
let self = this;
socket.on("message:new", data => {
socket.on("message:append", data => {
let history = self.props.history;
history.push(data);
self.setProps({
history: history
history: history.sort((a, b) => {
return a.createdAt - b.createAt;
})
});
self.scrollToBottom();
});