grab highest post number from the raw data, so deletions at the end of a topic work
This commit is contained in:
parent
9eb5c2a66a
commit
a8085f15c4
|
@ -5,7 +5,6 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
[:id,
|
[:id,
|
||||||
:title,
|
:title,
|
||||||
:posts_count,
|
:posts_count,
|
||||||
:highest_post_number,
|
|
||||||
:created_at,
|
:created_at,
|
||||||
:views,
|
:views,
|
||||||
:reply_count,
|
:reply_count,
|
||||||
|
@ -41,7 +40,8 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
:notification_level,
|
:notification_level,
|
||||||
:notifications_reason_id,
|
:notifications_reason_id,
|
||||||
:posts,
|
:posts,
|
||||||
:at_bottom
|
:at_bottom,
|
||||||
|
:highest_post_number
|
||||||
|
|
||||||
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
|
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
|
||||||
has_one :last_poster, serializer: BasicUserSerializer, embed: :objects
|
has_one :last_poster, serializer: BasicUserSerializer, embed: :objects
|
||||||
|
@ -185,7 +185,11 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
|
|
||||||
# Whether we're at the bottom of a topic (last page)
|
# Whether we're at the bottom of a topic (last page)
|
||||||
def at_bottom
|
def at_bottom
|
||||||
posts.present? and (@highest_number_in_posts == object.topic.highest_post_number)
|
posts.present? and (@highest_number_in_posts == object.highest_post_number)
|
||||||
|
end
|
||||||
|
|
||||||
|
def highest_post_number
|
||||||
|
object.highest_post_number
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
|
|
|
@ -223,6 +223,15 @@ class TopicView
|
||||||
@suggested_topics ||= TopicQuery.new(@user).list_suggested_for(topic)
|
@suggested_topics ||= TopicQuery.new(@user).list_suggested_for(topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This is pending a larger refactor, that allows custom orders
|
||||||
|
# for now we need to look for the highest_post_number in the stream
|
||||||
|
# the cache on topics is not correct if there are deleted posts at
|
||||||
|
# the end of the stream (for mods), nor is it correct for filtered
|
||||||
|
# streams
|
||||||
|
def highest_post_number
|
||||||
|
@highest_post_number ||= @posts.maximum(:post_number)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def read_posts_set
|
def read_posts_set
|
||||||
|
|
|
@ -106,10 +106,12 @@ describe TopicView do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allows admins to see deleted posts' do
|
it 'allows admins to see deleted posts' do
|
||||||
|
post_number = p3.post_number
|
||||||
p3.destroy
|
p3.destroy
|
||||||
admin = Fabricate(:admin)
|
admin = Fabricate(:admin)
|
||||||
topic_view = TopicView.new(topic.id, admin)
|
topic_view = TopicView.new(topic.id, admin)
|
||||||
topic_view.posts.count.should == 3
|
topic_view.posts.count.should == 3
|
||||||
|
topic_view.highest_post_number.should == post_number
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not allow non admins to see deleted posts' do
|
it 'does not allow non admins to see deleted posts' do
|
||||||
|
@ -117,7 +119,7 @@ describe TopicView do
|
||||||
topic_view.posts.count.should == 2
|
topic_view.posts.count.should == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sam: disabled for now, we only need this for poss, if we do, roll it into topic
|
# Sam: disabled for now, we only need this for polls, if we do, roll it into topic
|
||||||
# having to walk every post action is not really a good idea
|
# having to walk every post action is not really a good idea
|
||||||
#
|
#
|
||||||
# context '.voted_in_topic?' do
|
# context '.voted_in_topic?' do
|
||||||
|
|
Loading…
Reference in New Issue