discourse/app/serializers/user_bookmark_serializer.rb
Martin Brennan 49f4c548ef
FEATURE: Bookmark pinning (#12431)
Users can now pin bookmarks from their bookmark list. This will anchor the bookmark to the top of the list, and show a pin icon next to it. This also applies in the nav bookmarks panel. If there are multiple pinned bookmarks they sort by last updated order.
2021-03-22 09:50:22 +10:00

116 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require_relative 'post_item_excerpt'
class UserBookmarkSerializer < ApplicationSerializer
include PostItemExcerpt
include TopicTagsMixin
attributes :id,
:created_at,
:updated_at,
:topic_id,
:linked_post_number,
:post_id,
:name,
:reminder_at,
:pinned,
:title,
:deleted,
:hidden,
:category_id,
:closed,
:archived,
:archetype,
:highest_post_number,
:bumped_at,
:slug,
:post_user_username,
:post_user_avatar_template,
:post_user_name
def topic
@topic ||= object.topic || Topic.unscoped.find(object.topic_id)
end
def post
@post ||= object.post || Post.unscoped.find(object.post_id)
end
def closed
topic.closed
end
def archived
topic.archived
end
def linked_post_number
post.post_number
end
def title
topic.title
end
def deleted
topic.deleted_at.present? || post.deleted_at.present?
end
def hidden
post.hidden
end
def category_id
topic.category_id
end
def archetype
topic.archetype
end
def archived
topic.archived
end
def closed
topic.closed
end
def highest_post_number
topic.highest_post_number
end
def bumped_at
topic.bumped_at
end
def raw
post.raw
end
def cooked
post.cooked
end
def slug
topic.slug
end
def post_user
@post_user ||= post.user
end
def post_user_username
post_user.username
end
def post_user_avatar_template
post_user.avatar_template
end
def post_user_name
post_user.name
end
end