Commit 6acbe45e authored by lain's avatar lain
Browse files

Builder: Extract common features of likes and reactions.

parent ef55d240
Pipeline #25487 failed with stages
in 8 minutes and 26 seconds
...@@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do ...@@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
@spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()} @spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()}
def emoji_react(actor, object, emoji) do def emoji_react(actor, object, emoji) do
with {:ok, data, meta} <- like(actor, object) do with {:ok, data, meta} <- object_action(actor, object) do
data = data =
data data
|> Map.put("content", emoji) |> Map.put("content", emoji)
...@@ -64,6 +64,17 @@ def delete(actor, object_id) do ...@@ -64,6 +64,17 @@ def delete(actor, object_id) do
@spec like(User.t(), Object.t()) :: {:ok, map(), keyword()} @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
def like(actor, object) do def like(actor, object) do
with {:ok, data, meta} <- object_action(actor, object) do
data =
data
|> Map.put("type", "Like")
{:ok, data, meta}
end
end
@spec object_action(User.t(), Object.t()) :: {:ok, map(), keyword()}
defp object_action(actor, object) do
object_actor = User.get_cached_by_ap_id(object.data["actor"]) object_actor = User.get_cached_by_ap_id(object.data["actor"])
# Address the actor of the object, and our actor's follower collection if the post is public. # Address the actor of the object, and our actor's follower collection if the post is public.
...@@ -85,7 +96,6 @@ def like(actor, object) do ...@@ -85,7 +96,6 @@ def like(actor, object) do
%{ %{
"id" => Utils.generate_activity_id(), "id" => Utils.generate_activity_id(),
"actor" => actor.ap_id, "actor" => actor.ap_id,
"type" => "Like",
"object" => object.data["id"], "object" => object.data["id"],
"to" => to, "to" => to,
"cc" => cc, "cc" => cc,
......
Supports Markdown
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