2022-04-21 17:23:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserTopicBookmarkSerializer < UserPostTopicBookmarkBaseSerializer
|
2022-08-16 20:40:24 -05:00
|
|
|
attributes :last_read_post_number
|
|
|
|
|
2022-08-18 18:35:25 -05:00
|
|
|
# NOTE: It does not matter what the linked post number is for topic bookmarks,
|
|
|
|
# on the client we always take the user to the last unread post in the
|
|
|
|
# topic when the bookmark URL is clicked
|
2022-04-21 17:23:42 -05:00
|
|
|
def linked_post_number
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
def first_post
|
2022-08-24 01:01:29 -05:00
|
|
|
@first_post ||= topic.first_post
|
2022-04-21 17:23:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def deleted
|
|
|
|
topic.deleted_at.present? || first_post.deleted_at.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def hidden
|
|
|
|
first_post.hidden
|
|
|
|
end
|
|
|
|
|
|
|
|
def raw
|
|
|
|
first_post.raw
|
|
|
|
end
|
|
|
|
|
|
|
|
def cooked
|
2022-08-18 18:35:25 -05:00
|
|
|
first_post.cooked
|
2022-04-21 17:23:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bookmarkable_user
|
|
|
|
@bookmarkable_user ||= first_post.user
|
|
|
|
end
|
|
|
|
|
2022-05-10 18:29:24 -05:00
|
|
|
# NOTE: In the UI there are special topic-status and topic-link components to
|
|
|
|
# display the topic URL, this is only used for certain routes like the .ics bookmarks.
|
|
|
|
def bookmarkable_url
|
2022-08-08 09:24:04 -05:00
|
|
|
if @options[:link_to_first_unread_post]
|
|
|
|
Topic.url(topic_id, slug, (last_read_post_number || 0) + 1)
|
|
|
|
else
|
|
|
|
topic.url
|
|
|
|
end
|
2022-05-10 18:29:24 -05:00
|
|
|
end
|
|
|
|
|
2022-08-16 20:40:24 -05:00
|
|
|
def last_read_post_number
|
|
|
|
topic_user&.last_read_post_number
|
|
|
|
end
|
|
|
|
|
2022-04-21 17:23:42 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def topic
|
|
|
|
object.bookmarkable
|
|
|
|
end
|
2022-08-16 20:40:24 -05:00
|
|
|
|
|
|
|
def topic_user
|
|
|
|
topic.user_data
|
|
|
|
end
|
2022-04-21 17:23:42 -05:00
|
|
|
end
|