mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
@@ -5,13 +5,17 @@ require_dependency 'gaps'
|
||||
|
||||
class TopicView
|
||||
|
||||
attr_reader :topic, :posts, :guardian, :filtered_posts, :chunk_size
|
||||
attr_reader :topic, :posts, :guardian, :filtered_posts, :chunk_size, :print
|
||||
attr_accessor :draft, :draft_key, :draft_sequence, :user_custom_fields, :post_custom_fields
|
||||
|
||||
def self.slow_chunk_size
|
||||
10
|
||||
end
|
||||
|
||||
def self.print_chunk_size
|
||||
1000
|
||||
end
|
||||
|
||||
def self.chunk_size
|
||||
20
|
||||
end
|
||||
@@ -37,6 +41,7 @@ class TopicView
|
||||
@user = user
|
||||
@guardian = Guardian.new(@user)
|
||||
@topic = find_topic(topic_id)
|
||||
@print = options[:print].present?
|
||||
check_and_raise_exceptions
|
||||
|
||||
options.each do |key, value|
|
||||
@@ -44,7 +49,11 @@ class TopicView
|
||||
end
|
||||
|
||||
@page = 1 if (!@page || @page.zero?)
|
||||
@chunk_size = options[:slow_platform] ? TopicView.slow_chunk_size : TopicView.chunk_size
|
||||
@chunk_size = case
|
||||
when options[:slow_platform] then TopicView.slow_chunk_size
|
||||
when @print then TopicView.print_chunk_size
|
||||
else TopicView.chunk_size
|
||||
end
|
||||
@limit ||= @chunk_size
|
||||
|
||||
setup_filtered_posts
|
||||
@@ -71,7 +80,7 @@ class TopicView
|
||||
end
|
||||
|
||||
def canonical_path
|
||||
path = @topic.relative_url
|
||||
path = relative_url
|
||||
path << if @post_number
|
||||
page = ((@post_number.to_i - 1) / @limit) + 1
|
||||
(page > 1) ? "?page=#{page}" : ""
|
||||
@@ -113,22 +122,22 @@ class TopicView
|
||||
|
||||
def prev_page_path
|
||||
if prev_page > 1
|
||||
"#{@topic.relative_url}?page=#{prev_page}"
|
||||
"#{relative_url}?page=#{prev_page}"
|
||||
else
|
||||
@topic.relative_url
|
||||
relative_url
|
||||
end
|
||||
end
|
||||
|
||||
def next_page_path
|
||||
"#{@topic.relative_url}?page=#{next_page}"
|
||||
"#{relative_url}?page=#{next_page}"
|
||||
end
|
||||
|
||||
def absolute_url
|
||||
"#{Discourse.base_url}#{@topic.relative_url}"
|
||||
"#{Discourse.base_url}#{relative_url}"
|
||||
end
|
||||
|
||||
def relative_url
|
||||
@topic.relative_url
|
||||
"#{@topic.relative_url}#{@print ? '/print' : ''}"
|
||||
end
|
||||
|
||||
def page_title
|
||||
|
||||
Reference in New Issue
Block a user