also suppress link previews from posts marked #nsfw
authorWilliam Pitcock <nenolod@dereferenced.org>
Fri, 17 May 2019 20:42:51 +0000 (20:42 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Fri, 17 May 2019 22:13:24 +0000 (22:13 +0000)
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/common_api/utils.ex
test/web/rich_media/helpers_test.exs

index a599ffee558e678830cd782d733ce859bed474ac..5a312d673fe9cd793c235d0e1b018412d029cba6 100644 (file)
@@ -157,6 +157,7 @@ defmodule Pleroma.Web.CommonAPI do
          {to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
          context <- make_context(in_reply_to),
          cw <- data["spoiler_text"] || "",
+         sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
          full_payload <- String.trim(status <> cw),
          length when length in 1..limit <- String.length(full_payload),
          object <-
@@ -169,7 +170,8 @@ defmodule Pleroma.Web.CommonAPI do
              in_reply_to,
              tags,
              cw,
-             cc
+             cc,
+             sensitive
            ),
          object <-
            Map.put(
index bee2fd159a2beec8bdebea14dec19562f962ab1d..8d616097694a570f01b6e382e657250a50b83486 100644 (file)
@@ -223,7 +223,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
         in_reply_to,
         tags,
         cw \\ nil,
-        cc \\ []
+        cc \\ [],
+        sensitive \\ false
       ) do
     object = %{
       "type" => "Note",
@@ -231,6 +232,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
       "cc" => cc,
       "content" => content_html,
       "summary" => cw,
+      "sensitive" => sensitive,
       "context" => context,
       "attachment" => attachments,
       "actor" => actor,
index 6e23392caba2e3644e0dbabdd3ab80dc7511043c..53b0596f582d08f7a971fe56e3d126f95c371f53 100644 (file)
@@ -67,7 +67,26 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
     {:ok, activity} =
       CommonAPI.post(user, %{
         "status" => "http://example.com/ogp",
-        "spoiler_text" => "."
+        "sensitive" => true
+      })
+
+    %Object{} = object = Object.normalize(activity)
+
+    assert object.data["sensitive"]
+
+    Pleroma.Config.put([:rich_media, :enabled], true)
+
+    assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+    Pleroma.Config.put([:rich_media, :enabled], false)
+  end
+
+  test "refuses to crawl URLs from posts tagged NSFW" do
+    user = insert(:user)
+
+    {:ok, activity} =
+      CommonAPI.post(user, %{
+        "status" => "http://example.com/ogp #nsfw"
       })
 
     %Object{} = object = Object.normalize(activity)