From: lambda Date: Sat, 18 Nov 2017 15:58:44 +0000 (+0000) Subject: Merge branch 'formatting-fixes' into 'develop' X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;h=ed3403ad8be255480d7e41f899d74fe9e5ef3f84;hp=31e4277ba5a2a793a0bc94f5d7682a48349583a3;p=akkoma Merge branch 'formatting-fixes' into 'develop' Formatting fixes Closes #80 See merge request pleroma/pleroma!22 --- diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 27e2adc16..fbcbca979 100644 --- 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 index 9ae7b095a..9bc7f2ce6 100644 --- 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/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index bbd003b06..e1256c7b6 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -579,7 +579,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do {:ok, token} <- Token.exchange_token(app, auth) do conn |> put_session(:oauth_token, token.token) - |> redirect(to: "/web/timelines/public") + |> redirect(to: "/web/getting-started") end end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index a00a11f8b..c8b929501 100644 --- 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)