API: return whether post or item was already reported or not
This commit is contained in:
parent
8068d8747b
commit
6dbef95951
6 changed files with 29 additions and 9 deletions
|
|
@ -104,7 +104,7 @@ module Api
|
|||
end
|
||||
|
||||
def comment_as_json(comment)
|
||||
CommentPresenter.new(comment).as_api_response
|
||||
CommentPresenter.new(comment, current_user).as_api_response
|
||||
end
|
||||
|
||||
def find_post
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ class CommentPresenter < BasePresenter
|
|||
body: message.plain_text_for_json,
|
||||
author: PersonPresenter.new(author).as_api_json,
|
||||
created_at: created_at,
|
||||
mentioned_people: build_mentioned_people_json
|
||||
mentioned_people: build_mentioned_people_json,
|
||||
reported: current_user.present? && reports.where(user: current_user).exists?
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -162,13 +162,15 @@ class PostPresenter < BasePresenter
|
|||
{
|
||||
liked: @post.likes.where(author: current_user.person).exists?,
|
||||
reshared: @post.reshares.where(author: current_user.person).exists?,
|
||||
subscribed: participates?
|
||||
subscribed: participates?,
|
||||
reported: @post.reports.where(user: current_user).exists?
|
||||
}
|
||||
else
|
||||
{
|
||||
liked: false,
|
||||
reshared: false,
|
||||
subscribed: false
|
||||
subscribed: false,
|
||||
reported: false
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -100,9 +100,10 @@
|
|||
"mentioned_people": {
|
||||
"type": "array",
|
||||
"items": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/short_profile" }
|
||||
}
|
||||
},
|
||||
"reported": { "type": "boolean" }
|
||||
},
|
||||
"required": ["guid", "created_at", "author", "body"],
|
||||
"required": ["guid", "created_at", "author", "body", "reported"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
|
|
@ -282,9 +283,10 @@
|
|||
"properties": {
|
||||
"liked": { "type": "boolean" },
|
||||
"reshared": { "type": "boolean" },
|
||||
"subscribed": { "type": "boolean" }
|
||||
"subscribed": { "type": "boolean" },
|
||||
"reported": { "type": "boolean" }
|
||||
},
|
||||
"required": ["liked", "reshared", "subscribed"],
|
||||
"required": ["liked", "reshared", "subscribed", "reported"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"mentioned_people": {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ describe Api::V1::CommentsController do
|
|||
before do
|
||||
@comment_text1 = "This is a comment"
|
||||
@comment_text2 = "This is a comment 2"
|
||||
comment_service.create(@status.guid, @comment_text1)
|
||||
@comment1 = comment_service.create(@status.guid, @comment_text1)
|
||||
comment_service.create(@status.guid, @comment_text2)
|
||||
end
|
||||
|
||||
|
|
@ -154,9 +154,21 @@ describe Api::V1::CommentsController do
|
|||
expect(comments.length).to eq(2)
|
||||
confirm_comment_format(comments[0], auth.user, @comment_text1)
|
||||
confirm_comment_format(comments[1], auth.user, @comment_text2)
|
||||
expect(comments).to all(include("reported" => false))
|
||||
|
||||
expect(comments.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/comments")
|
||||
end
|
||||
|
||||
it "returns reported status of a comment" do
|
||||
auth_minimum_scopes.user.reports.create!(item: @comment1, text: "Meh!")
|
||||
get(
|
||||
api_v1_post_comments_path(post_id: @status.guid),
|
||||
params: {access_token: access_token_minimum_scopes}
|
||||
)
|
||||
comments = response_body(response)
|
||||
expect(comments[0]["reported"]).to eq(true)
|
||||
expect(comments[1]["reported"]).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context "wrong post id" do
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ describe Api::V1::PostsController do
|
|||
it "gets post" do
|
||||
auth.user.like!(@status)
|
||||
auth.user.reshare!(@status)
|
||||
auth.user.reports.create!(item: @status, text: "Meh!")
|
||||
@status.reload
|
||||
|
||||
get(
|
||||
|
|
@ -123,6 +124,7 @@ describe Api::V1::PostsController do
|
|||
expect(post["own_interaction_state"]["liked"]).to be true
|
||||
expect(post["own_interaction_state"]["reshared"]).to be true
|
||||
expect(post["own_interaction_state"]["subscribed"]).to be true
|
||||
expect(post["own_interaction_state"]["reported"]).to be true
|
||||
|
||||
expect(post.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/post")
|
||||
end
|
||||
|
|
@ -722,6 +724,7 @@ describe Api::V1::PostsController do
|
|||
expect(state["liked"]).to eq(reference_post.likes.where(author: auth.user.person).exists?)
|
||||
expect(state["reshared"]).to eq(reference_post.reshares.where(author: auth.user.person).exists?)
|
||||
expect(state["subscribed"]).to eq(reference_post.participations.where(author: auth.user.person).exists?)
|
||||
expect(state["reported"]).to eq(reference_post.reports.where(user: auth.user).exists?)
|
||||
end
|
||||
|
||||
def confirm_person_format(post_person, user)
|
||||
|
|
|
|||
Loading…
Reference in a new issue