Merge pull request #3721 from riking/patch-1
FEATURE: Include topic title, category in posts.json
This commit is contained in:
commit
5dca462b5a
|
@ -37,7 +37,8 @@ class PostsController < ApplicationController
|
|||
.where('posts.id <= ?', last_post_id)
|
||||
.where('posts.id > ?', last_post_id - 50)
|
||||
.includes(topic: :category)
|
||||
.includes(:user)
|
||||
.includes(user: :primary_group)
|
||||
.includes(:reply_to_user)
|
||||
.limit(50)
|
||||
# Remove posts the user doesn't have permission to see
|
||||
# This isn't leaking any information we weren't already through the post ID numbers
|
||||
|
@ -58,6 +59,7 @@ class PostsController < ApplicationController
|
|||
scope: guardian,
|
||||
root: 'latest_posts',
|
||||
add_raw: true,
|
||||
add_title: true,
|
||||
all_post_actions: counts)
|
||||
)
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ class PostSerializer < BasicPostSerializer
|
|||
:topic_view,
|
||||
:parent_post,
|
||||
:add_raw,
|
||||
:add_title,
|
||||
:single_post_link_counts,
|
||||
:draft_sequence,
|
||||
:post_actions,
|
||||
|
@ -28,6 +29,9 @@ class PostSerializer < BasicPostSerializer
|
|||
:yours,
|
||||
:topic_id,
|
||||
:topic_slug,
|
||||
:topic_title,
|
||||
:topic_html_title,
|
||||
:category_id,
|
||||
:display_username,
|
||||
:primary_group_name,
|
||||
:version,
|
||||
|
@ -73,6 +77,30 @@ class PostSerializer < BasicPostSerializer
|
|||
object.try(:topic).try(:slug)
|
||||
end
|
||||
|
||||
def include_topic_title?
|
||||
@add_title
|
||||
end
|
||||
|
||||
def include_topic_html_title?
|
||||
@add_title
|
||||
end
|
||||
|
||||
def include_category_id?
|
||||
@add_title
|
||||
end
|
||||
|
||||
def topic_title
|
||||
object.topic.title
|
||||
end
|
||||
|
||||
def topic_html_title
|
||||
object.topic.fancy_title
|
||||
end
|
||||
|
||||
def category_id
|
||||
object.topic.category_id
|
||||
end
|
||||
|
||||
def moderator?
|
||||
!!(object.try(:user).try(:moderator?))
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue