Merge branch 'formatting-fixes' into 'develop'
authorlambda <pleromagit@rogerbraun.net>
Sat, 18 Nov 2017 15:58:44 +0000 (15:58 +0000)
committerlambda <pleromagit@rogerbraun.net>
Sat, 18 Nov 2017 15:58:44 +0000 (15:58 +0000)
Formatting fixes

Closes #80

See merge request pleroma/pleroma!22

lib/pleroma/formatter.ex
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index 27e2adc16b7298d0ed9d117a23abc0a4e2bd258d..fbcbca9796e7e6dba95b9b32b8dba5a94d204a78 100644 (file)
@@ -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
index 9ae7b095a4ed08cbcc23dc2c92c49d0250fc5a50..9bc7f2ce6b5aebc287aa71d6e5c4ec7de603c05d 100644 (file)
@@ -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"],
index bbd003b06420d42a2fef5554774f8e4eb811d151..e1256c7b642f637176e0d83dafcf5e628c031a0e 100644 (file)
@@ -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
 
index a00a11f8b46aec3929c58fcfc377ef3f499e521c..c8b9295018be66672f530ce67e0e979bf82d7f26 100644 (file)
@@ -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)