FEATURE: Scroll to new posts when user is near bottom of PM.

This commit is contained in:
Guo Xiang Tan 2016-11-09 13:37:13 +08:00
parent 2d2998f5e0
commit 74e1889924
1 changed files with 22 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import Composer from 'discourse/models/composer';
import DiscourseURL from 'discourse/lib/url';
import { categoryBadgeHTML } from 'discourse/helpers/category-link';
import Post from 'discourse/models/post';
import debounce from 'discourse/lib/debounce';
export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
composer: Ember.inject.controller(),
@ -668,6 +669,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
const topic = this.get('model');
const postStream = topic.get('postStream');
const post = postStream.findLoadedPost(postId);
if (post) {
DiscourseURL.routeTo(topic.urlForPostNumber(post.get('post_number')));
} else {
@ -838,10 +840,30 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
topic.reload().then(() => {
this.send('postChangedRoute', topic.get('post_number') || 1);
});
} else {
const postNumber = data.post_number;
const notInPostStream = topic.get('highest_post_number') <= postNumber;
const postNumberDifference = postNumber - topic.get('currentPost');
if (notInPostStream &&
topic.get('isPrivateMessage') &&
postNumberDifference > 0 &&
postNumberDifference < 7) {
this._scrollToPost(data.post_number);
}
}
});
},
_scrollToPost: debounce(function(postNumber) {
const $post = $(`.topic-post article#post_${postNumber}`);
if ($post.length === 0) return;
$('body').animate({ scrollTop: $post.offset().top }, 1000);
}, 500),
unsubscribe() {
const topicId = this.get('content.id');
if (!topicId) return;