Skip to content

A platform for community discussion. Free, open, simple.

Trim `WebHookTopicSerializer` further.

Guo Xiang Tan3ff0074e9dfa
diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb
index 7ca94fd87a6..44479aa7e0a 100644
--- a/app/serializers/topic_view_serializer.rb
+++ b/app/serializers/topic_view_serializer.rb
@@ -36,7 +36,6 @@ class TopicViewSerializer < ApplicationSerializer
:deleted_at,
:pending_posts_count,
:user_id,
- :pm_with_non_human_user?,
:featured_link,
:featured_link_root_domain,
:pinned_globally,
@@ -67,7 +66,8 @@ class TopicViewSerializer < ApplicationSerializer
:unicode_title,
:message_bus_last_id,
:participant_count,
- :destination_category_id
+ :destination_category_id,
+ :pm_with_non_human_user,
# TODO: Split off into proper object / serializer
def details
@@ -281,6 +281,10 @@ class TopicViewSerializer < ApplicationSerializer
private_message?(object.topic)
end
+ def pm_with_non_human_user
+ object.topic.pm_with_non_human_user?
+ end
+
def participant_count
object.participant_count
end
diff --git a/app/serializers/web_hook_topic_view_serializer.rb b/app/serializers/web_hook_topic_view_serializer.rb
index 8c1aa0a3a72..1aa71ccfd19 100644
--- a/app/serializers/web_hook_topic_view_serializer.rb
+++ b/app/serializers/web_hook_topic_view_serializer.rb
@@ -1,6 +1,8 @@
require_dependency 'pinned_check'
class WebHookTopicViewSerializer < TopicViewSerializer
+ attributes :created_by,
+ :last_poster
%i{
post_stream
@@ -11,9 +13,24 @@ class WebHookTopicViewSerializer < TopicViewSerializer
draft_sequence
message_bus_last_id
suggested_topics
+ has_summary
+ actions_summary
+ current_post_number
+ chunk_size
+ topic_timer
+ private_topic_timer
+ details
}.each do |attr|
define_method("include_#{attr}?") do
false
end
end
+
+ def created_by
+ BasicUserSerializer.new(object.topic.user, scope: scope, root: false)
+ end
+
+ def last_poster
+ BasicUserSerializer.new(object.topic.last_poster, scope: scope, root: false)
+ end
end
diff --git a/spec/serializers/web_hook_topic_view_serializer_spec.rb b/spec/serializers/web_hook_topic_view_serializer_spec.rb
index 2f120b26566..d7ee1005555 100644
--- a/spec/serializers/web_hook_topic_view_serializer_spec.rb
+++ b/spec/serializers/web_hook_topic_view_serializer_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe WebHookTopicViewSerializer do
it 'should only include the required keys' do
count = serializer.as_json.keys.count
- difference = count - 35
+ difference = count - 30
expect(difference).to eq(0), lambda {
message = ""