Builder.note/1: return {:ok, map(), keyword()} like other Builder functions
authorAlex Gleason <alex@alexgleason.me>
Sat, 14 Aug 2021 16:24:55 +0000 (11:24 -0500)
committerAlex Gleason <alex@alexgleason.me>
Sat, 14 Aug 2021 16:24:55 +0000 (11:24 -0500)
lib/pleroma/web/activity_pub/builder.ex
lib/pleroma/web/common_api/activity_draft.ex
test/pleroma/web/activity_pub/builder_test.exs

index 3b1fa4dba1d88774b41bee2660d86fe0ead76de8..647ccf432d9ef60fe953e05332c42025000137c5 100644 (file)
@@ -126,21 +126,25 @@ defmodule Pleroma.Web.ActivityPub.Builder do
      |> Pleroma.Maps.put_if_present("context", context), []}
   end
 
+  @spec note(ActivityDraft.t()) :: {:ok, map(), keyword()}
   def note(%ActivityDraft{} = draft) do
-    %{
-      "type" => "Note",
-      "to" => draft.to,
-      "cc" => draft.cc,
-      "content" => draft.content_html,
-      "summary" => draft.summary,
-      "sensitive" => draft.sensitive,
-      "context" => draft.context,
-      "attachment" => draft.attachments,
-      "actor" => draft.user.ap_id,
-      "tag" => Keyword.values(draft.tags) |> Enum.uniq()
-    }
-    |> add_in_reply_to(draft.in_reply_to)
-    |> Map.merge(draft.extra)
+    data =
+      %{
+        "type" => "Note",
+        "to" => draft.to,
+        "cc" => draft.cc,
+        "content" => draft.content_html,
+        "summary" => draft.summary,
+        "sensitive" => draft.sensitive,
+        "context" => draft.context,
+        "attachment" => draft.attachments,
+        "actor" => draft.user.ap_id,
+        "tag" => Keyword.values(draft.tags) |> Enum.uniq()
+      }
+      |> add_in_reply_to(draft.in_reply_to)
+      |> Map.merge(draft.extra)
+
+    {:ok, data, []}
   end
 
   defp add_in_reply_to(object, nil), do: object
index a5cfb3403f0f6b085acc5d37b2545cf1094b78ce..b4e3e37aec3bff82db68577af9a768a690dad18d 100644 (file)
@@ -214,8 +214,10 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
 
     emoji = Map.merge(emoji, summary_emoji)
 
+    {:ok, note_data, _meta} = Builder.note(draft)
+
     object =
-      Builder.note(draft)
+      note_data
       |> Map.put("emoji", emoji)
       |> Map.put("source", draft.status)
       |> Map.put("generator", draft.params[:generator])
index 103521c96032bcc28af6a9e0444551e9586808ce..3fe32bce5d24e3852500d1ec2257e4269d3f5d86 100644 (file)
@@ -28,19 +28,21 @@ defmodule Pleroma.Web.ActivityPub.BuilderTest do
         extra: %{"custom_tag" => "test"}
       }
 
-      assert Builder.note(draft) == %{
-               "actor" => user.ap_id,
-               "attachment" => [],
-               "cc" => [user3.ap_id],
-               "content" => "<h1>This is :moominmamma: note</h1>",
-               "context" => "2hu",
-               "sensitive" => false,
-               "summary" => "test summary",
-               "tag" => ["jimm"],
-               "to" => [user2.ap_id],
-               "type" => "Note",
-               "custom_tag" => "test"
-             }
+      expected = %{
+        "actor" => user.ap_id,
+        "attachment" => [],
+        "cc" => [user3.ap_id],
+        "content" => "<h1>This is :moominmamma: note</h1>",
+        "context" => "2hu",
+        "sensitive" => false,
+        "summary" => "test summary",
+        "tag" => ["jimm"],
+        "to" => [user2.ap_id],
+        "type" => "Note",
+        "custom_tag" => "test"
+      }
+
+      assert {:ok, ^expected, []} = Builder.note(draft)
     end
   end
 end