poc including badges in post stream

This commit is contained in:
Mark VanLandingham 2024-10-07 11:39:35 -05:00
parent 41c3c5745e
commit 40c4d06bdd
No known key found for this signature in database
GPG Key ID: 3522A75A293C836D
3 changed files with 23 additions and 0 deletions

View File

@ -58,6 +58,8 @@ class Post < ActiveRecord::Base
has_many :user_actions, foreign_key: :target_post_id
has_many :user_badges
belongs_to :image_upload, class_name: "Upload"
has_many :post_hotlinked_media, dependent: :destroy, class_name: "PostHotlinkedMedia"

View File

@ -39,6 +39,7 @@ class PostSerializer < BasicPostSerializer
:flair_color,
:flair_group_id,
:version,
:badges,
:can_edit,
:can_delete,
:can_permanently_delete,
@ -584,6 +585,25 @@ class PostSerializer < BasicPostSerializer
UserStatusSerializer.new(object.user&.user_status, root: false)
end
def include_badges?
badges.present?
end
def badges
@badges ||=
begin
badges = object.user_badges.filter { |badge| badge.user_id == object.user_id }
return if badges.blank?
ActiveModel::ArraySerializer.new(
badges,
each_serializer: UserBadgeSerializer,
scope: scope,
root: false,
)
end
end
def mentioned_users
users =
if @topic_view && (mentioned_users = @topic_view.mentioned_users[object.id])

View File

@ -859,6 +859,7 @@ class TopicView
:deleted_by,
:incoming_email,
:image_upload,
:user_badges,
)
@posts = @posts.includes({ user: :user_status }) if SiteSetting.enable_user_status