From 47887ac8489d929f6c948814a8bacd14fc579ab9 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Mon, 18 Dec 2017 16:56:03 +0100 Subject: [PATCH] MastoAPI: Fix always-sensitive bugs. --- lib/pleroma/formatter.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index c98db2d94..a482c74e4 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -10,7 +10,7 @@ defmodule Pleroma.Formatter do def parse_tags(text, data \\ %{}) do Regex.scan(@tag_regex, text) |> Enum.map(fn (["#" <> tag = full_tag]) -> {full_tag, String.downcase(tag)} end) - |> (fn map -> if data["sensitive"], do: [{"#nsfw", "nsfw"}] ++ map, else: map end).() + |> (fn map -> if data["sensitive"] in [true, "True", "true"], do: [{"#nsfw", "nsfw"}] ++ map, else: map end).() end def parse_mentions(text) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index e50f53ba4..a17068be8 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -162,7 +162,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def public_timeline(%{assigns: %{user: user}} = conn, params) do params = params |> Map.put("type", ["Create", "Announce"]) - |> Map.put("local_only", !!params["local"]) + |> Map.put("local_only", params["local"] in [true, "True", "true"]) |> Map.put("blocking_user", user) activities = ActivityPub.fetch_public_activities(params) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 8bfad5265..80e15f35e 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -35,7 +35,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do {:ok, [_activity]} = OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873") conn = conn - |> get("/api/v1/timelines/public") + |> get("/api/v1/timelines/public", %{"local" => "False"}) assert length(json_response(conn, 200)) == 2 @@ -50,9 +50,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do conn = conn |> assign(:user, user) - |> post("/api/v1/statuses", %{"status" => "cofe", "spoiler_text" => "2hu"}) + |> post("/api/v1/statuses", %{"status" => "cofe", "spoiler_text" => "2hu", "sensitive" => "false"}) - assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu"} = json_response(conn, 200) + assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} = json_response(conn, 200) assert Repo.get(Activity, id) end