diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index e860ddc49c..3139fa3bd3 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -116,7 +116,7 @@ var onFocus = function() { if (this.$el.css('display') !== 'none') { - this.updateUnread({scroll: false}); + this.markRead(); } }.bind(this); this.window.addEventListener('focus', onFocus); @@ -206,8 +206,8 @@ this.$('.bottom-bar form').addClass('active'); }, - updateUnread: function(options) { - this.updateLastSeenIndicator(options); + updateUnread: function() { + this.updateLastSeenIndicator(); this.model.markRead(); }, @@ -251,11 +251,8 @@ } }, - removeLastSeenIndicator: function(options) { - options = options || {}; - _.defaults(options, {force: false}); - - if (this.lastSeenIndicator && (options.force || this.lastSeenIndicator.isOldEnough())) { + removeLastSeenIndicator: function() { + if (this.lastSeenIndicator) { this.lastSeenIndicator.remove(); this.lastSeenIndicator = null; } @@ -283,9 +280,9 @@ }); var unreadCount = this.model.get('unreadCount'); - if (oldestUnread && unreadCount > 0) { - this.removeLastSeenIndicator({force: true}); + this.removeLastSeenIndicator(); + if (oldestUnread && unreadCount > 0) { this.lastSeenIndicator = new Whisper.LastSeenIndicatorView({count: unreadCount}); var unreadEl = this.lastSeenIndicator.render().$el; @@ -303,9 +300,6 @@ } }.bind(this), 1); } - else { - this.removeLastSeenIndicator({force: false}); - } }, focusMessageField: function() { @@ -368,18 +362,24 @@ this.model.messageCollection.add(message, {merge: true}); message.setToExpire(); - // if the last seen indicator is old enough, it will go away. + // If the last seen indicator is old enough, it will go away. // if it isn't, we want to make sure it's up to date if (this.lastSeenIndicator) { this.lastSeenIndicator.increment(1); } if (!this.isHidden() && !window.isFocused()) { + // The conversation is visible, but window is not focused this.updateLastSeenIndicator({scroll: false}); } else if (!this.isHidden() && window.isFocused()) { - this.removeLastSeenIndicator(); - this.markRead(); + // The conversation is visible and in focus + + if (this.view.atBottom()) { + this.markRead(); + } else { + this.updateLastSeenIndicator({scroll: false}); + } } }, updateMessage: function(message) { diff --git a/js/views/last_seen_indicator_view.js b/js/views/last_seen_indicator_view.js index bef573a4b1..f7bb0011ba 100644 --- a/js/views/last_seen_indicator_view.js +++ b/js/views/last_seen_indicator_view.js @@ -13,14 +13,6 @@ initialize: function(options) { options = options || {}; this.count = options.count || 0; - this.start = Date.now(); - }, - - isOldEnough: function() { - var now = Date.now(); - if (now - this.start > FIVE_SECONDS) { - return true; - } }, increment: function(count) {