Preserve lastSeenIndicator location when not focused

Also, a couple name changes of ConversationView methods to better
reflect what they do. update -> reset, since the method is destructive.

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-06-01 11:54:57 -07:00
parent 944ae296eb
commit 672a517b73
2 changed files with 14 additions and 6 deletions

View file

@ -158,7 +158,7 @@
'blur .send-message': 'unfocusBottomBar', 'blur .send-message': 'unfocusBottomBar',
'loadMore .message-list': 'loadMoreMessages', 'loadMore .message-list': 'loadMoreMessages',
'newOffscreenMessage .message-list': 'addScrollDownButtonWithCount', 'newOffscreenMessage .message-list': 'addScrollDownButtonWithCount',
'atBottom .message-list': 'hideScrollDownButton', 'atBottom .message-list': 'removeScrollDownButton',
'farFromBottom .message-list': 'addScrollDownButton', 'farFromBottom .message-list': 'addScrollDownButton',
'lazyScroll .message-list': 'onLazyScroll', 'lazyScroll .message-list': 'onLazyScroll',
'close .menu': 'closeMenu', 'close .menu': 'closeMenu',
@ -216,7 +216,7 @@
} }
}, },
updateUnread: function() { updateUnread: function() {
this.updateLastSeenIndicator(); this.resetLastSeenIndicator();
this.markRead(); this.markRead();
}, },
@ -253,7 +253,7 @@
} }
}, },
hideScrollDownButton: function() { removeScrollDownButton: function() {
if (this.scrollDownButton) { if (this.scrollDownButton) {
this.scrollDownButton.remove(); this.scrollDownButton.remove();
this.scrollDownButton = null; this.scrollDownButton = null;
@ -282,7 +282,7 @@
this.view.scrollToBottom(); this.view.scrollToBottom();
}, },
updateLastSeenIndicator: function(options) { resetLastSeenIndicator: function(options) {
options = options || {}; options = options || {};
_.defaults(options, {scroll: true}); _.defaults(options, {scroll: true});
@ -379,7 +379,11 @@
if (!this.isHidden() && !window.isFocused()) { if (!this.isHidden() && !window.isFocused()) {
// The conversation is visible, but window is not focused // The conversation is visible, but window is not focused
this.updateLastSeenIndicator({scroll: false}); if (!this.lastSeenIndicator) {
this.resetLastSeenIndicator({scroll: false});
} else if (this.view.atBottom() && this.model.get('unreadCount') === this.lastSeenIndicator.getCount()) {
this.lastSeenIndicator.el.scrollIntoView();
}
} }
else if (!this.isHidden() && window.isFocused()) { else if (!this.isHidden() && window.isFocused()) {
// The conversation is visible and in focus // The conversation is visible and in focus
@ -388,7 +392,7 @@
// When we're scrolled up and we don't already have a last seen indicator // When we're scrolled up and we don't already have a last seen indicator
// we add a new one. // we add a new one.
if (!this.view.atBottom() && !this.lastSeenIndicator) { if (!this.view.atBottom() && !this.lastSeenIndicator) {
this.updateLastSeenIndicator({scroll: false}); this.resetLastSeenIndicator({scroll: false});
} }
} }
}, },

View file

@ -20,6 +20,10 @@
this.render(); this.render();
}, },
getCount: function() {
return this.count;
},
render_attributes: function() { render_attributes: function() {
var unreadMessages = this.count === 1 ? i18n('unreadMessage') var unreadMessages = this.count === 1 ? i18n('unreadMessage')
: i18n('unreadMessages', [this.count]); : i18n('unreadMessages', [this.count]);