diff --git a/app/controllers/api/v1/comments_controller.rb b/app/controllers/api/v1/comments_controller.rb index 52ddf88f542..1e1811536ff 100644 --- a/app/controllers/api/v1/comments_controller.rb +++ b/app/controllers/api/v1/comments_controller.rb @@ -104,7 +104,7 @@ def post_service end def comment_as_json(comment) - CommentPresenter.new(comment).as_api_response + CommentPresenter.new(comment, current_user).as_api_response end def find_post diff --git a/app/presenters/comment_presenter.rb b/app/presenters/comment_presenter.rb index 17af876884e..6a290337eb4 100644 --- a/app/presenters/comment_presenter.rb +++ b/app/presenters/comment_presenter.rb @@ -18,7 +18,8 @@ def as_api_response 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 diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index aa8cae29243..8f8d67e5c34 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -162,13 +162,15 @@ def build_own_interaction_state { 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 diff --git a/lib/schemas/api_v1.json b/lib/schemas/api_v1.json index c4b7dbd9f5e..c5ec76db031 100644 --- a/lib/schemas/api_v1.json +++ b/lib/schemas/api_v1.json @@ -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": { diff --git a/spec/integration/api/comments_controller_spec.rb b/spec/integration/api/comments_controller_spec.rb index d3d7a7f1fda..0b4cdfd6d23 100644 --- a/spec/integration/api/comments_controller_spec.rb +++ b/spec/integration/api/comments_controller_spec.rb @@ -139,7 +139,7 @@ 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 @@ 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 diff --git a/spec/integration/api/posts_controller_spec.rb b/spec/integration/api/posts_controller_spec.rb index 4941194948e..b858cbfd9e8 100644 --- a/spec/integration/api/posts_controller_spec.rb +++ b/spec/integration/api/posts_controller_spec.rb @@ -109,6 +109,7 @@ 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 @@ 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 @@ def confirm_own_interaction_state(state, reference_post) 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)