Transmogrify outgoing nsfw.
authorlain <lain@soykaf.club>
Sun, 18 Feb 2018 13:07:13 +0000 (14:07 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Feb 2018 13:07:13 +0000 (14:07 +0100)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs

index 17cd3b1c2754ad4edf30f6015729d1c91ac8700c..fc04cc9a119db51ee10581d4bee71010be908b97 100644 (file)
@@ -100,6 +100,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   """
   def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
     object = object
+    |> set_sensitive
     |> add_hashtags
     |> add_mention_tags
     |> add_attributed_to
@@ -144,6 +145,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     Map.put(object, "conversation", object["context"])
   end
 
+  def set_sensitive(object) do
+    tags = object["tag"] || []
+    Map.put(object, "sensitive", "nsfw" in tags)
+  end
+
   def add_attributed_to(object) do
     attributedTo = object["attributedTo"] || object["actor"]
 
index ec608a86a019d710548720313c6e9e50ab90d3e8..6271e200edfdac094119c99ef32ad1071d3d9858 100644 (file)
@@ -120,6 +120,15 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert Enum.member?(object["tag"], expected_mention)
     end
 
+    test "it adds the sensitive property" do
+      user = insert(:user)
+
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
+      {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+      assert modified["object"]["sensitive"]
+    end
+
     test "it adds the json-ld context and the conversation property" do
       user = insert(:user)