mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
Rename TopicView#last_read_post_id
to TopicView#filtered_post_id
.
This commit is contained in:
parent
cb69888758
commit
cfa7898c2d
@ -187,7 +187,7 @@ class TopicViewSerializer < ApplicationSerializer
|
|||||||
|
|
||||||
def last_read_post_id
|
def last_read_post_id
|
||||||
return nil unless last_read_post_number
|
return nil unless last_read_post_number
|
||||||
object.last_read_post_id(last_read_post_number)
|
object.filtered_post_id(last_read_post_number)
|
||||||
end
|
end
|
||||||
alias_method :include_last_read_post_id?, :has_topic_user?
|
alias_method :include_last_read_post_id?, :has_topic_user?
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ class TopicView
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_read_post_id(post_number)
|
def filtered_post_id(post_number)
|
||||||
@filtered_posts.where(post_number: post_number).pluck(:id).first
|
@filtered_posts.where(post_number: post_number).pluck(:id).first
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -566,16 +566,16 @@ class TopicView
|
|||||||
|
|
||||||
def closest_post_to(post_number)
|
def closest_post_to(post_number)
|
||||||
# happy path
|
# happy path
|
||||||
closest_post = @filtered_posts.where("post_number = ?", post_number).limit(1).pluck(:id)
|
closest_post_id = filtered_post_id(post_number)
|
||||||
|
|
||||||
if closest_post.empty?
|
if closest_post_id.blank?
|
||||||
# less happy path, missing post
|
# less happy path, missing post
|
||||||
closest_post = @filtered_posts.order("@(post_number - #{post_number})").limit(1).pluck(:id)
|
closest_post_id = @filtered_posts.order("@(post_number - #{post_number})").limit(1).pluck(:id).first
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil if closest_post.empty?
|
return nil if closest_post_id.blank?
|
||||||
|
|
||||||
filtered_post_ids.index(closest_post.first) || filtered_post_ids[0]
|
filtered_post_ids.index(closest_post_id) || filtered_post_ids[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
MEGA_TOPIC_POSTS_COUNT = 10000
|
MEGA_TOPIC_POSTS_COUNT = 10000
|
||||||
|
@ -583,12 +583,12 @@ describe TopicView do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#last_read_post_id' do
|
describe '#filtered_post_id' do
|
||||||
it 'should return the right id' do
|
it 'should return the right id' do
|
||||||
post = Fabricate(:post, topic: topic)
|
post = Fabricate(:post, topic: topic)
|
||||||
|
|
||||||
expect(topic_view.last_read_post_id(nil)).to eq(nil)
|
expect(topic_view.filtered_post_id(nil)).to eq(nil)
|
||||||
expect(topic_view.last_read_post_id(post.post_number)).to eq(post.id)
|
expect(topic_view.filtered_post_id(post.post_number)).to eq(post.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user