diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index fc7189d5..9dd5bd7b 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -12,10 +12,12 @@ var Whisper = Whisper || {}; this.$el.html(Mustache.render(this.template)); this.view = new Whisper.MessageListView({collection: this.model.messages()}); + this.listenTo(this.model.messages(), 'add', this.scrollToBottom); + this.model.messages().fetch({reset: true}); this.$el.find('.discussion-container').append(this.view.el); window.addEventListener('storage', (function(){ - this.fetch(); + this.model.messages().fetch(); }).bind(this)); }, events: { @@ -23,10 +25,6 @@ var Whisper = Whisper || {}; 'close': 'remove' }, - fetch: function() { - this.model.messages().fetch({reset: true}); - }, - sendMessage: function(e) { e.preventDefault(); var input = this.$el.find('.send input'); @@ -36,8 +34,13 @@ var Whisper = Whisper || {}; } }, + scrollToBottom: function() { + this.view.$el.scrollTop(this.view.el.scrollHeight); + }, + render: function() { Whisper.Layout.setContent(this.$el.show()); + this.scrollToBottom(); return this; } });