mirror of
https://github.com/discourse/discourse.git
synced 2025-02-24 07:42:11 +08:00
FEATURE: add first_post_id to TopicListItemSerializer (#31254)
Will be used in this feature: https://github.com/discourse/discourse-topic-cards/pull/36
This commit is contained in:
parent
50136ee4e6
commit
85a95e9aa1
@ -12,6 +12,7 @@ class TopicListItemSerializer < ListableTopicSerializer
|
||||
:op_like_count,
|
||||
:op_can_like,
|
||||
:op_liked,
|
||||
:first_post_id,
|
||||
:pinned_globally,
|
||||
:liked_post_numbers,
|
||||
:featured_link,
|
||||
@ -70,6 +71,15 @@ class TopicListItemSerializer < ListableTopicSerializer
|
||||
).exists?
|
||||
end
|
||||
|
||||
def include_first_post_id?
|
||||
theme_modifier_helper.serialize_topic_op_likes_data
|
||||
end
|
||||
|
||||
def first_post_id
|
||||
return false if !object.first_post
|
||||
object.first_post.id
|
||||
end
|
||||
|
||||
def last_poster_username
|
||||
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
||||
end
|
||||
|
@ -149,5 +149,23 @@ RSpec.describe TopicListItemSerializer do
|
||||
|
||||
expect(json.key?(:op_liked)).to eq(false)
|
||||
end
|
||||
|
||||
it "serializes first_post_id" do
|
||||
allow_any_instance_of(ThemeModifierHelper).to receive(
|
||||
:serialize_topic_op_likes_data,
|
||||
).and_return(true)
|
||||
json = TopicListItemSerializer.new(topic, scope: Guardian.new(moderator), root: false).as_json
|
||||
|
||||
expect(json[:first_post_id]).to eq(first_post.id)
|
||||
end
|
||||
|
||||
it "does not include op_can_like when theme modifier disallows" do
|
||||
allow_any_instance_of(ThemeModifierHelper).to receive(
|
||||
:serialize_topic_op_likes_data,
|
||||
).and_return(false)
|
||||
json = TopicListItemSerializer.new(topic, scope: Guardian.new(moderator), root: false).as_json
|
||||
|
||||
expect(json.key?(:first_post_id)).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user