discourse/app/serializers/group_post_serializer.rb
Keegan George 7b76d25946
DEV: Adopt post list component and new posts route front-end (#30604)
Recently we introduced a new `PostList` component (d886c55f63). In this update, we make broader adoption of this component. In particular, these areas include using the new component in the user activity stream pages, user's deleted posts, and pending posts page. This update also takes the existing `posts` route and adds a barebones front-end for it to view posts all in one page.

---------

Co-authored-by: David Taylor <david@taylorhq.com>
2025-01-23 10:20:45 -08:00

73 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require_relative "post_item_excerpt"
class GroupPostSerializer < ApplicationSerializer
include PostItemExcerpt
attributes :id,
:created_at,
:topic_id,
:topic_title,
:topic_slug,
:topic_html_title,
:url,
:category_id,
:post_number,
:posts_count,
:post_type,
:username,
:name,
:avatar_template,
:user_title,
:primary_group_name
# TODO(keegan): Remove `embed: :object` after updating references in discourse-reactions
has_one :user, serializer: GroupPostUserSerializer, embed: :object
has_one :topic, serializer: BasicTopicSerializer, embed: :object
def topic_title
object.topic.title
end
def topic_html_title
object.topic.fancy_title
end
def topic_slug
object.topic.slug
end
def posts_count
object.topic.posts_count
end
def include_user_long_name?
SiteSetting.enable_names?
end
def category_id
object.topic.category_id
end
def username
object&.user&.username
end
def name
object&.user&.name
end
def avatar_template
object&.user&.avatar_template
end
def user_title
object&.user&.title
end
def primary_group_name
object&.user&.primary_group&.name
end
end