mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 20:33:38 +08:00
0c42a1e5f3
Allows creating a bookmark with the `for_topic` flag introduced ind1d2298a4c
set to true. This happens when clicking on the Bookmark button in the topic footer when no other posts are bookmarked. In a later PR, when clicking on these topic-level bookmarks the user will be taken to the last unread post in the topic, not the OP. Only the OP can have a topic level bookmark, and users can also make a post-level bookmark on the OP of the topic. I had to do some pretty heavy refactors because most of the bookmark code in the JS topics controller was centred around instances of Post JS models, but the topic level bookmark is not centred around a post. Some refactors were just for readability as well. Also removes some missed reminderType code from the purge in41e19adb0d
126 lines
1.8 KiB
Ruby
126 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,
|
|
:fancy_title,
|
|
:deleted,
|
|
:hidden,
|
|
:category_id,
|
|
:closed,
|
|
:archived,
|
|
:archetype,
|
|
:highest_post_number,
|
|
:bumped_at,
|
|
:slug,
|
|
:post_user_username,
|
|
:post_user_avatar_template,
|
|
:post_user_name,
|
|
:for_topic
|
|
|
|
def topic_id
|
|
post.topic_id
|
|
end
|
|
|
|
def topic
|
|
@topic ||= object.topic
|
|
end
|
|
|
|
def post
|
|
@post ||= object.post
|
|
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 fancy_title
|
|
topic.fancy_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
|