A platform for community discussion. Free, open, simple.
Rename `TopicView#last_read_post_id` to `TopicView#filtered_post_id`.
Guo Xiang Tancfa7898c2d54
diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rbindex a34a22fb505..a14dd9ff301 100644--- a/app/serializers/topic_view_serializer.rb+++ b/app/serializers/topic_view_serializer.rb@@ -187,7 +187,7 @@ class TopicViewSerializer < ApplicationSerializerdef last_read_post_idreturn nil unless last_read_post_number- object.last_read_post_id(last_read_post_number)+ object.filtered_post_id(last_read_post_number)endalias_method :include_last_read_post_id?, :has_topic_user?diff --git a/lib/topic_view.rb b/lib/topic_view.rbindex 8289ccbdf4a..be2819d8e1e 100644--- a/lib/topic_view.rb+++ b/lib/topic_view.rb@@ -412,7 +412,7 @@ class TopicViewendend- def last_read_post_id(post_number)+ def filtered_post_id(post_number)@filtered_posts.where(post_number: post_number).pluck(:id).firstend@@ -566,16 +566,16 @@ class TopicViewdef closest_post_to(post_number)# 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- 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).firstend- 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]endMEGA_TOPIC_POSTS_COUNT = 10000diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rbindex 78f7a32585e..2f54bc6cf0f 100644--- a/spec/components/topic_view_spec.rb+++ b/spec/components/topic_view_spec.rb@@ -583,12 +583,12 @@ describe TopicView doendend- describe '#last_read_post_id' do+ describe '#filtered_post_id' doit 'should return the right id' dopost = Fabricate(:post, topic: topic)- expect(topic_view.last_read_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(nil)).to eq(nil)+ expect(topic_view.filtered_post_id(post.post_number)).to eq(post.id)endendend