FEATURE: add max_reply_history to limit number of replies
that can be expanded, when clicking "in-reply-to"
This commit is contained in:
parent
6d3d425611
commit
1cc37e32b9
|
@ -649,7 +649,7 @@ Discourse.PostStream = Em.Object.extend({
|
||||||
**/
|
**/
|
||||||
findReplyHistory: function(post) {
|
findReplyHistory: function(post) {
|
||||||
var postStream = this,
|
var postStream = this,
|
||||||
url = "/posts/" + post.get('id') + "/reply-history.json";
|
url = "/posts/" + post.get('id') + "/reply-history.json?max_replies=" + Discourse.SiteSettings.max_reply_history;
|
||||||
|
|
||||||
return Discourse.ajax(url).then(function(result) {
|
return Discourse.ajax(url).then(function(result) {
|
||||||
return result.map(function (p) {
|
return result.map(function (p) {
|
||||||
|
|
|
@ -158,7 +158,7 @@ class PostsController < ApplicationController
|
||||||
|
|
||||||
def reply_history
|
def reply_history
|
||||||
post = find_post_from_params
|
post = find_post_from_params
|
||||||
render_serialized(post.reply_history, PostSerializer)
|
render_serialized(post.reply_history(params[:max_replies].to_i), PostSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -476,7 +476,7 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def reply_history
|
def reply_history(max_replies=100)
|
||||||
post_ids = Post.exec_sql("WITH RECURSIVE breadcrumb(id, reply_to_post_number) AS (
|
post_ids = Post.exec_sql("WITH RECURSIVE breadcrumb(id, reply_to_post_number) AS (
|
||||||
SELECT p.id, p.reply_to_post_number FROM posts AS p
|
SELECT p.id, p.reply_to_post_number FROM posts AS p
|
||||||
WHERE p.id = :post_id
|
WHERE p.id = :post_id
|
||||||
|
@ -486,7 +486,12 @@ class Post < ActiveRecord::Base
|
||||||
AND p.topic_id = :topic_id
|
AND p.topic_id = :topic_id
|
||||||
) SELECT id from breadcrumb ORDER by id", post_id: id, topic_id: topic_id).to_a
|
) SELECT id from breadcrumb ORDER by id", post_id: id, topic_id: topic_id).to_a
|
||||||
|
|
||||||
post_ids.map! {|r| r['id'].to_i }.reject! {|post_id| post_id == id}
|
post_ids.map! {|r| r['id'].to_i }
|
||||||
|
.reject! {|post_id| post_id == id}
|
||||||
|
|
||||||
|
# [1,2,3][-10,-1] => nil
|
||||||
|
post_ids = (post_ids[(0-max_replies)..-1] || post_ids)
|
||||||
|
|
||||||
Post.where(id: post_ids).includes(:user, :topic).order(:id).to_a
|
Post.where(id: post_ids).includes(:user, :topic).order(:id).to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -741,6 +741,7 @@ en:
|
||||||
suppress_reply_directly_below: "Don't show the expandable reply count on a post when there is only a single reply directly below this post."
|
suppress_reply_directly_below: "Don't show the expandable reply count on a post when there is only a single reply directly below 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_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."
|
||||||
|
max_reply_history: "Maximum number of replies to expand when expanding in-reply-to"
|
||||||
|
|
||||||
experimental_reply_expansion: "Hide intermediate replies when expanding a reply to (experimental)"
|
experimental_reply_expansion: "Hide intermediate replies when expanding a reply to (experimental)"
|
||||||
|
|
||||||
|
|
|
@ -347,6 +347,9 @@ posting:
|
||||||
default: true
|
default: true
|
||||||
suppress_reply_when_quoting:
|
suppress_reply_when_quoting:
|
||||||
default: true
|
default: true
|
||||||
|
max_reply_history:
|
||||||
|
default: 1
|
||||||
|
client: true
|
||||||
experimental_reply_expansion:
|
experimental_reply_expansion:
|
||||||
default: false
|
default: false
|
||||||
client: true
|
client: true
|
||||||
|
|
|
@ -715,6 +715,7 @@ describe Post do
|
||||||
|
|
||||||
it "returns the posts in reply to this post" do
|
it "returns the posts in reply to this post" do
|
||||||
p4.reply_history.should == [p1, p2]
|
p4.reply_history.should == [p1, p2]
|
||||||
|
p4.reply_history(1).should == [p2]
|
||||||
p3.reply_history.should be_blank
|
p3.reply_history.should be_blank
|
||||||
p2.reply_history.should == [p1]
|
p2.reply_history.should == [p1]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue