From 9a0a87ab405caa298c5ab2cb41b44b7a7bc20370 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 30 May 2017 14:36:45 -0700 Subject: [PATCH] Last seen indicator: dismissed only on open and send It can be moved if you're not scrolled to the bottom of of the window or the window doesn't have focus when a new message comes in. Other than that, it marches up the window until you close and reopen the conversation, or send a message. Note that we do NOT mark messages as read if they come in when you are scrolled up. But we do mark the entire conversation as read if you switch away from the app and back. FREEBIE --- js/views/conversation_view.js | 32 ++++++++++++++-------------- js/views/last_seen_indicator_view.js | 8 ------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index e860ddc49..3139fa3bd 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 bef573a4b..f7bb0011b 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) {