mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
Force summary mode when user enters at the top of megalodoon topics.
This commit is contained in:
parent
f7d22bad90
commit
9a7a079f4d
@ -177,9 +177,9 @@ export default function transformPost(
|
||||
|
||||
const postStream = topic.get("postStream");
|
||||
postAtts.userFilters = postStream.userFilters;
|
||||
postAtts.topicSummaryEnabled = postStream.summary;
|
||||
postAtts.topicSummaryEnabled = postStream.summary || topic.force_summary_mode;
|
||||
postAtts.topicWordCount = topic.word_count;
|
||||
postAtts.hasTopicSummary = topic.has_summary;
|
||||
postAtts.hasTopicSummary = topic.has_summary || topic.force_summary_mode;
|
||||
}
|
||||
|
||||
if (postAtts.isDeleted) {
|
||||
|
@ -68,6 +68,7 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
:participant_count,
|
||||
:destination_category_id,
|
||||
:pm_with_non_human_user,
|
||||
:force_summary_mode,
|
||||
|
||||
# TODO: Split off into proper object / serializer
|
||||
def details
|
||||
@ -299,6 +300,10 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
object.topic.shared_draft.present?
|
||||
end
|
||||
|
||||
def force_summary_mode
|
||||
object.force_summary_mode?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def private_message?(topic)
|
||||
|
@ -405,6 +405,11 @@ class TopicView
|
||||
end
|
||||
end
|
||||
|
||||
def force_summary_mode?
|
||||
@force_summary_mode ||=
|
||||
(@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2))
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def read_posts_set
|
||||
@ -482,7 +487,7 @@ class TopicView
|
||||
@filtered_posts = unfiltered_posts
|
||||
|
||||
# Filters
|
||||
if @filter == 'summary' || force_summary_mode?
|
||||
if @filter == 'summary' || ((@post_number.blank? || @post_number.to_i == 1) && force_summary_mode?)
|
||||
@filtered_posts = @filtered_posts.summary(@topic.id)
|
||||
@contains_gaps = true unless force_summary_mode?
|
||||
end
|
||||
@ -572,9 +577,4 @@ class TopicView
|
||||
def is_mega_topic?
|
||||
@topic.posts_count >= MEGA_TOPIC_POSTS_COUNT
|
||||
end
|
||||
|
||||
def force_summary_mode?
|
||||
@force_summary_mode ||=
|
||||
(@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2))
|
||||
end
|
||||
end
|
||||
|
@ -365,22 +365,31 @@ describe TopicView do
|
||||
end
|
||||
|
||||
describe 'when a megalodon topic is closed' do
|
||||
before do
|
||||
@original_const = TopicView::MEGA_TOPIC_POSTS_COUNT
|
||||
TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
|
||||
TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 1)
|
||||
topic.update!(closed: true)
|
||||
SiteSetting.summary_max_results = 2
|
||||
end
|
||||
|
||||
after do
|
||||
TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
|
||||
TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", @original_const)
|
||||
end
|
||||
|
||||
it 'should be forced into summary mode without gaps' do
|
||||
begin
|
||||
original_const = TopicView::MEGA_TOPIC_POSTS_COUNT
|
||||
TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
|
||||
TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 1)
|
||||
SiteSetting.summary_max_results = 2
|
||||
topic.update!(closed: true)
|
||||
topic_view = TopicView.new(topic.id, evil_trout, post_number: 1)
|
||||
|
||||
topic_view = TopicView.new(topic.id, evil_trout)
|
||||
expect(topic_view.contains_gaps?).to eq(false)
|
||||
expect(topic_view.posts).to eq([p5])
|
||||
end
|
||||
|
||||
expect(topic_view.contains_gaps?).to eq(false)
|
||||
expect(topic_view.posts).to eq([p5])
|
||||
ensure
|
||||
TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
|
||||
TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", original_const)
|
||||
end
|
||||
it 'should not be forced into summary mode if post_number is not blank' do
|
||||
topic_view = TopicView.new(topic.id, evil_trout, post_number: 2)
|
||||
|
||||
expect(topic_view.contains_gaps?).to eq(false)
|
||||
expect(topic_view.posts).to eq([p1, p2, p3])
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user