Verified Commit ba6049aa authored by Alex Gleason's avatar Alex Gleason
Browse files

Builder.note/1: return {:ok, map(), keyword()} like other Builder functions

parent a2eacfc5
Pipeline #37147 passed with stages
in 9 minutes and 53 seconds
...@@ -126,21 +126,25 @@ def create(actor, object, recipients) do ...@@ -126,21 +126,25 @@ def create(actor, object, recipients) do
|> Pleroma.Maps.put_if_present("context", context), []} |> Pleroma.Maps.put_if_present("context", context), []}
end end
@spec note(ActivityDraft.t()) :: {:ok, map(), keyword()}
def note(%ActivityDraft{} = draft) do def note(%ActivityDraft{} = draft) do
%{ data =
"type" => "Note", %{
"to" => draft.to, "type" => "Note",
"cc" => draft.cc, "to" => draft.to,
"content" => draft.content_html, "cc" => draft.cc,
"summary" => draft.summary, "content" => draft.content_html,
"sensitive" => draft.sensitive, "summary" => draft.summary,
"context" => draft.context, "sensitive" => draft.sensitive,
"attachment" => draft.attachments, "context" => draft.context,
"actor" => draft.user.ap_id, "attachment" => draft.attachments,
"tag" => Keyword.values(draft.tags) |> Enum.uniq() "actor" => draft.user.ap_id,
} "tag" => Keyword.values(draft.tags) |> Enum.uniq()
|> add_in_reply_to(draft.in_reply_to) }
|> Map.merge(draft.extra) |> add_in_reply_to(draft.in_reply_to)
|> Map.merge(draft.extra)
{:ok, data, []}
end end
defp add_in_reply_to(object, nil), do: object defp add_in_reply_to(object, nil), do: object
......
...@@ -214,8 +214,10 @@ defp object(draft) do ...@@ -214,8 +214,10 @@ defp object(draft) do
emoji = Map.merge(emoji, summary_emoji) emoji = Map.merge(emoji, summary_emoji)
{:ok, note_data, _meta} = Builder.note(draft)
object = object =
Builder.note(draft) note_data
|> Map.put("emoji", emoji) |> Map.put("emoji", emoji)
|> Map.put("source", draft.status) |> Map.put("source", draft.status)
|> Map.put("generator", draft.params[:generator]) |> Map.put("generator", draft.params[:generator])
......
...@@ -28,19 +28,21 @@ test "returns note data" do ...@@ -28,19 +28,21 @@ test "returns note data" do
extra: %{"custom_tag" => "test"} extra: %{"custom_tag" => "test"}
} }
assert Builder.note(draft) == %{ expected = %{
"actor" => user.ap_id, "actor" => user.ap_id,
"attachment" => [], "attachment" => [],
"cc" => [user3.ap_id], "cc" => [user3.ap_id],
"content" => "<h1>This is :moominmamma: note</h1>", "content" => "<h1>This is :moominmamma: note</h1>",
"context" => "2hu", "context" => "2hu",
"sensitive" => false, "sensitive" => false,
"summary" => "test summary", "summary" => "test summary",
"tag" => ["jimm"], "tag" => ["jimm"],
"to" => [user2.ap_id], "to" => [user2.ap_id],
"type" => "Note", "type" => "Note",
"custom_tag" => "test" "custom_tag" => "test"
} }
assert {:ok, ^expected, []} = Builder.note(draft)
end end
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment