Skip to content

Commit

Permalink
Preserve lastSeenIndicator location when not focused
Browse files Browse the repository at this point in the history
Also, a couple name changes of ConversationView methods to better
reflect what they do. update -> reset, since the method is destructive.

FREEBIE
  • Loading branch information
scottnonnenberg committed Jun 1, 2017
1 parent 944ae29 commit 672a517
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions js/views/conversation_view.js
Expand Up @@ -158,7 +158,7 @@
'blur .send-message': 'unfocusBottomBar',
'loadMore .message-list': 'loadMoreMessages',
'newOffscreenMessage .message-list': 'addScrollDownButtonWithCount',
'atBottom .message-list': 'hideScrollDownButton',
'atBottom .message-list': 'removeScrollDownButton',
'farFromBottom .message-list': 'addScrollDownButton',
'lazyScroll .message-list': 'onLazyScroll',
'close .menu': 'closeMenu',
Expand Down Expand Up @@ -216,7 +216,7 @@
}
},
updateUnread: function() {
this.updateLastSeenIndicator();
this.resetLastSeenIndicator();
this.markRead();
},

Expand Down Expand Up @@ -253,7 +253,7 @@
}
},

hideScrollDownButton: function() {
removeScrollDownButton: function() {
if (this.scrollDownButton) {
this.scrollDownButton.remove();
this.scrollDownButton = null;
Expand Down Expand Up @@ -282,7 +282,7 @@
this.view.scrollToBottom();
},

updateLastSeenIndicator: function(options) {
resetLastSeenIndicator: function(options) {
options = options || {};
_.defaults(options, {scroll: true});

Expand Down Expand Up @@ -379,7 +379,11 @@

if (!this.isHidden() && !window.isFocused()) {
// 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()) {
// The conversation is visible and in focus
Expand All @@ -388,7 +392,7 @@
// When we're scrolled up and we don't already have a last seen indicator
// we add a new one.
if (!this.view.atBottom() && !this.lastSeenIndicator) {
this.updateLastSeenIndicator({scroll: false});
this.resetLastSeenIndicator({scroll: false});
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions js/views/last_seen_indicator_view.js
Expand Up @@ -20,6 +20,10 @@
this.render();
},

getCount: function() {
return this.count;
},

render_attributes: function() {
var unreadMessages = this.count === 1 ? i18n('unreadMessage')
: i18n('unreadMessages', [this.count]);
Expand Down

0 comments on commit 672a517

Please sign in to comment.