From f24e7c090554e49021c0600895bcd8dd9be7a005 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 3 Mar 2017 15:11:25 +0100 Subject: [PATCH] Remove scrollDownMessageHeight. Fix failing test --- spec/chatbox.js | 2 +- spec/chatroom.js | 6 +++--- src/converse-chatview.js | 24 +++++++++++------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/spec/chatbox.js b/spec/chatbox.js index 0d072e835..e529d30df 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -699,7 +699,7 @@ .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()); } }); - waits(50); + waits(500); // Give enough time for `markScrolled` to have been called runs(function () { chatboxview.$content.scrollTop(0); }); diff --git a/spec/chatroom.js b/spec/chatroom.js index 93b0e48b3..531f1c721 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -1089,8 +1089,8 @@ spyOn(view, 'scrollDown').andCallThrough(); runs(function () { /* Create enough messages so that there's a - * scrollbar. - */ + * scrollbar. + */ for (var i=0; i<20; i++) { _converse.chatboxes.onMessage( $msg({ @@ -1101,7 +1101,7 @@ }).c('body').t('Message: '+i).tree()); } }); - waits(50); + waits(500); // Give enough time for `markScrolled` to have been called runs(function () { view.$content.scrollTop(0); }); diff --git a/src/converse-chatview.js b/src/converse-chatview.js index 5461558ae..e1a77bd87 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -221,7 +221,7 @@ insert.call(that.$content, $el); return $el; }, - this.scrollDownMessageHeight.bind(this) + this.scrollDown.bind(this) )(this.renderMessage(attrs)); }, @@ -288,7 +288,7 @@ this.$content.find('.chat-message[data-isodate="'+msg_dates[idx]+'"]')); return $el; }.bind(this), - this.scrollDownMessageHeight.bind(this) + this.scrollDown.bind(this) )(this.renderMessage(attrs)); }, @@ -776,6 +776,13 @@ return this; }, + hideNewMessagesIndicator: function () { + var new_msgs_indicator = this.el.querySelector('.new-msgs-indicator'); + if (!_.isNull(new_msgs_indicator)) { + new_msgs_indicator.classList.add('hidden'); + } + }, + markScrolled: _.debounce(function (ev) { /* Called when the chat content is scrolled up or down. * We want to record when the user has scrolled away from @@ -795,8 +802,8 @@ (this.$content.scrollTop() + this.$content.innerHeight()) >= this.$content[0].scrollHeight-10; if (is_at_bottom) { + this.hideNewMessagesIndicator(); this.model.save('scrolled', false); - this.$el.find('.new-msgs-indicator').addClass('hidden'); } else { // We're not at the bottom of the chat area, so we mark // that the box is in a scrolled-up state. @@ -809,20 +816,11 @@ this.scrollDown(); }, - scrollDownMessageHeight: function ($message) { - if (this.$content.is(':visible') && !this.model.get('scrolled')) { - this.$content.scrollTop( - this.$content.scrollTop() + $message[0].scrollHeight); - this.model.save({'auto_scrolled': true}); - } - return this; - }, - _scrollDown: function () { /* Inner method that gets debounced */ if (this.$content.is(':visible') && !this.model.get('scrolled')) { this.$content.scrollTop(this.$content[0].scrollHeight); - this.$el.find('.new-msgs-indicator').addClass('hidden'); + this.hideNewMessagesIndicator(); this.model.save({'auto_scrolled': true}); } },