discourse/app/serializers/user_action_serializer.rb

98 lines
2.0 KiB
Ruby
Raw Normal View History

class UserActionSerializer < ApplicationSerializer
attributes :action_type,
:created_at,
:excerpt,
:avatar_template,
:acting_avatar_template,
:slug,
:topic_id,
:target_user_id,
:target_name,
:target_username,
:post_number,
:post_id,
:reply_to_post_number,
:username,
:name,
:user_id,
:acting_username,
:acting_name,
:acting_user_id,
:title,
:deleted,
2013-07-19 05:24:51 +08:00
:hidden,
:post_type,
:action_code,
:edit_reason,
:category_id,
:uploaded_avatar_id,
:letter_avatar_color,
:closed,
:archived,
:acting_uploaded_avatar_id,
:acting_letter_avatar_color
def excerpt
2015-04-22 02:36:46 +08:00
cooked = object.cooked || PrettyText.cook(object.raw)
PrettyText.excerpt(cooked, 300, keep_emojis: true) if cooked
end
def avatar_template
User.avatar_template(object.username, object.uploaded_avatar_id)
end
def acting_avatar_template
User.avatar_template(object.acting_username, object.acting_uploaded_avatar_id)
end
2015-04-22 02:36:46 +08:00
def include_acting_avatar_template?
object.acting_username.present?
end
def include_name?
SiteSetting.enable_names?
end
def include_target_name?
include_name?
end
def include_acting_name?
include_name?
end
def slug
Slug.for(object.title)
end
2015-04-22 02:36:46 +08:00
def include_slug?
object.title.present?
end
def include_reply_to_post_number?
object.action_type == UserAction::REPLY
end
def include_edit_reason?
object.action_type == UserAction::EDIT
end
def closed
object.topic_closed
end
def archived
object.topic_archived
end
def letter_avatar_color
User.letter_avatar_color(username)
end
def acting_letter_avatar_color
User.letter_avatar_color(acting_username)
end
end