2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

FEATURE: experimental reply-to expansion which hides intermediate posts

experimental_reply_expansion
This commit is contained in:
Sam 2014-10-15 18:13:01 +11:00
parent 9e9bfe03c0
commit 10db8f21d7
5 changed files with 71 additions and 16 deletions

View file

@ -9,9 +9,8 @@
export default Ember.Component.extend({ export default Ember.Component.extend({
classNameBindings: [':gap', 'gap::hidden'], classNameBindings: [':gap', 'gap::hidden'],
_setup: function() { initGaps: function(){
this.set('loading', false); this.set('loading', false);
var before = this.get('before') === 'true', var before = this.get('before') === 'true',
gaps = before ? this.get('postStream.gaps.before') : this.get('postStream.gaps.after'); gaps = before ? this.get('postStream.gaps.before') : this.get('postStream.gaps.after');
@ -20,6 +19,11 @@ export default Ember.Component.extend({
} }
}.on('init'), }.on('init'),
gapsChanged: function(){
this.initGaps();
this.rerender();
}.observes('post.hasGap'),
render: function(buffer) { render: function(buffer) {
if (this.get('loading')) { if (this.get('loading')) {
buffer.push(I18n.t('loading')); buffer.push(I18n.t('loading'));

View file

@ -259,6 +259,31 @@ Discourse.PostStream = Em.Object.extend({
}, },
hasLoadedData: Em.computed.and('hasPosts', 'hasStream'), hasLoadedData: Em.computed.and('hasPosts', 'hasStream'),
collapsePosts: function(from, to){
var posts = this.get('posts');
var remove = posts.filter(function(post){
var postNumber = post.get('post_number');
return postNumber >= from && postNumber <= to;
});
posts.removeObjects(remove);
// make gap
this.set('gaps', this.get('gaps') || {before: {}, after: {}});
var before = this.get('gaps.before');
var post = posts.find(function(post){
return post.get('post_number') > to;
});
before[post.get('id')] = remove.map(function(post){
return post.get('id');
});
post.set('hasGap', true);
this.get('stream').enumerableContentDidChange();
},
/** /**
Fill in a gap of posts before a particular post Fill in a gap of posts before a particular post
@ -291,6 +316,7 @@ Discourse.PostStream = Em.Object.extend({
delete self.get('gaps.before')[postId]; delete self.get('gaps.before')[postId];
self.get('stream').enumerableContentDidChange(); self.get('stream').enumerableContentDidChange();
post.set('hasGap', false);
}); });
} }
} }

View file

@ -177,13 +177,30 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
var replyHistory = post.get('replyHistory'), var replyHistory = post.get('replyHistory'),
topicController = this.get('controller'), topicController = this.get('controller'),
origScrollTop = $(window).scrollTop(); origScrollTop = $(window).scrollTop(),
replyPostNumber = this.get('post.reply_to_post_number'),
postNumber = this.get('post.post_number'),
self = this;
if (Discourse.Mobile.mobileView) { if (Discourse.Mobile.mobileView) {
Discourse.URL.routeTo(this.get('post.topic').urlForPostNumber(this.get('post.reply_to_post_number'))); Discourse.URL.routeTo(this.get('post.topic').urlForPostNumber(replyPostNumber));
return; return;
} }
var stream = topicController.get('postStream');
var offsetFromTop = this.$().position().top - $(window).scrollTop();
if(Discourse.SiteSettings.experimental_reply_expansion) {
if(postNumber - replyPostNumber > 1) {
stream.collapsePosts(replyPostNumber + 1, postNumber - 1);
}
Em.run.next(function() {
Discourse.PostView.highlight(replyPostNumber);
$(window).scrollTop(self.$().position().top - offsetFromTop);
});
return;
}
if (replyHistory.length > 0) { if (replyHistory.length > 0) {
var origHeight = this.$('.embedded-posts.top').height(); var origHeight = this.$('.embedded-posts.top').height();
@ -195,7 +212,6 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
} else { } else {
post.set('loadingReplyHistory', true); post.set('loadingReplyHistory', true);
var self = this;
topicController.get('postStream').findReplyHistory(post).then(function () { topicController.get('postStream').findReplyHistory(post).then(function () {
post.set('loadingReplyHistory', false); post.set('loadingReplyHistory', false);
@ -285,12 +301,7 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
}); });
Discourse.PostView.reopenClass({ Discourse.PostView.reopenClass({
considerHighlighting: function(controller, postNumber) { highlight: function(postNumber){
var highlightNumber = controller.get('highlightOnInsert');
// If we're meant to highlight a post
if (highlightNumber === postNumber) {
controller.set('highlightOnInsert', null);
var $contents = $('#post_' + postNumber +' .topic-body'), var $contents = $('#post_' + postNumber +' .topic-body'),
origColor = $contents.data('orig-color') || $contents.css('backgroundColor'); origColor = $contents.data('orig-color') || $contents.css('backgroundColor');
@ -302,6 +313,15 @@ Discourse.PostView.reopenClass({
$contents.removeClass('highlighted'); $contents.removeClass('highlighted');
$contents.css({'background-color': ''}); $contents.css({'background-color': ''});
}); });
},
considerHighlighting: function(controller, postNumber) {
var highlightNumber = controller.get('highlightOnInsert');
// If we're meant to highlight a post
if (highlightNumber === postNumber) {
controller.set('highlightOnInsert', null);
this.highlight(postNumber);
} }
} }
}); });

View file

@ -740,6 +740,8 @@ en:
suppress_reply_directly_above: "Don't show the expandable in-reply-to on a post when there is only a single reply directly above this post." suppress_reply_directly_above: "Don't show the expandable in-reply-to on a post when there is only a single reply directly above this post."
suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post quotes reply." suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post quotes reply."
experimental_reply_expansion: "Hide intermediate replies when expanding a reply to (experimental)"
topics_per_period_in_top_summary: "Number of top topics shown in the default top topics summary." topics_per_period_in_top_summary: "Number of top topics shown in the default top topics summary."
topics_per_period_in_top_page: "Number of top topics shown on the expanded 'Show More' top topics." topics_per_period_in_top_page: "Number of top topics shown on the expanded 'Show More' top topics."
redirect_users_to_top_page: "Automatically redirect new and long absent users to the top page." redirect_users_to_top_page: "Automatically redirect new and long absent users to the top page."

View file

@ -351,6 +351,9 @@ posting:
default: true default: true
suppress_reply_when_quoting: suppress_reply_when_quoting:
default: true default: true
experimental_reply_expansion:
default: false
client: true
post_undo_action_window_mins: 10 post_undo_action_window_mins: 10
max_mentions_per_post: 10 max_mentions_per_post: 10
newuser_max_replies_per_topic: 3 newuser_max_replies_per_topic: 3