logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: 7b397ed125b55172390a8143bfb21ecab571ad97
parent: 4647bcd6e647ad31ba492a6e712721b58bf47e83
Author: eal <eal@waifu.club>
Date:   Sat, 18 Nov 2017 14:34:37 +0000

Merge branch 'sensitive-content-bit' into 'develop'

Add #nsfw tag if sensitive content bit is set

Closes #78

See merge request pleroma/pleroma!23

Diffstat:

Mlib/pleroma/formatter.ex3++-
Mlib/pleroma/web/common_api/common_api.ex2+-
Mtest/web/mastodon_api/mastodon_api_controller_test.exs11+++++++++++
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex @@ -7,9 +7,10 @@ defmodule Pleroma.Formatter do end @tag_regex ~r/\#\w+/u - def parse_tags(text) 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).() end def parse_mentions(text) do diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex @@ -55,7 +55,7 @@ defmodule Pleroma.Web.CommonAPI do mentions <- Formatter.parse_mentions(status), inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]), to <- to_for_user_and_mentions(user, mentions, inReplyTo), - tags <- Formatter.parse_tags(status), + tags <- Formatter.parse_tags(status, data), content_html <- make_content_html(status, mentions, attachments, tags), context <- make_context(inReplyTo), cw <- data["spoiler_text"], diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -56,6 +56,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert Repo.get(Activity, id) end + test "posting a sensitive status", %{conn: conn} do + user = insert(:user) + + conn = conn + |> assign(:user, user) + |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true}) + + assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200) + assert Repo.get(Activity, id) + end + test "replying to a status", %{conn: conn} do user = insert(:user)