poc including badges in post stream
This commit is contained in:
parent
41c3c5745e
commit
40c4d06bdd
|
@ -58,6 +58,8 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :user_actions, foreign_key: :target_post_id
|
has_many :user_actions, foreign_key: :target_post_id
|
||||||
|
|
||||||
|
has_many :user_badges
|
||||||
|
|
||||||
belongs_to :image_upload, class_name: "Upload"
|
belongs_to :image_upload, class_name: "Upload"
|
||||||
|
|
||||||
has_many :post_hotlinked_media, dependent: :destroy, class_name: "PostHotlinkedMedia"
|
has_many :post_hotlinked_media, dependent: :destroy, class_name: "PostHotlinkedMedia"
|
||||||
|
|
|
@ -39,6 +39,7 @@ class PostSerializer < BasicPostSerializer
|
||||||
:flair_color,
|
:flair_color,
|
||||||
:flair_group_id,
|
:flair_group_id,
|
||||||
:version,
|
:version,
|
||||||
|
:badges,
|
||||||
:can_edit,
|
:can_edit,
|
||||||
:can_delete,
|
:can_delete,
|
||||||
:can_permanently_delete,
|
:can_permanently_delete,
|
||||||
|
@ -584,6 +585,25 @@ class PostSerializer < BasicPostSerializer
|
||||||
UserStatusSerializer.new(object.user&.user_status, root: false)
|
UserStatusSerializer.new(object.user&.user_status, root: false)
|
||||||
end
|
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
|
def mentioned_users
|
||||||
users =
|
users =
|
||||||
if @topic_view && (mentioned_users = @topic_view.mentioned_users[object.id])
|
if @topic_view && (mentioned_users = @topic_view.mentioned_users[object.id])
|
||||||
|
|
|
@ -859,6 +859,7 @@ class TopicView
|
||||||
:deleted_by,
|
:deleted_by,
|
||||||
:incoming_email,
|
:incoming_email,
|
||||||
:image_upload,
|
:image_upload,
|
||||||
|
:user_badges,
|
||||||
)
|
)
|
||||||
|
|
||||||
@posts = @posts.includes({ user: :user_status }) if SiteSetting.enable_user_status
|
@posts = @posts.includes({ user: :user_status }) if SiteSetting.enable_user_status
|
||||||
|
|
Loading…
Reference in New Issue