alias Ecto.{Changeset, UUID}
import Ecto.Query
+ # Some implementations send the actor URI as the actor field, others send the entire actor object,
+ # so figure out what the actor's URI is based on what we have.
+ def normalize_actor(actor) do
+ cond do
+ is_binary(actor) ->
+ actor
+
+ is_map(actor) ->
+ actor["id"]
+ end
+ end
+
+ def normalize_params(params) do
+ Map.put(params, "actor", normalize_actor(params["actor"]))
+ end
+
def make_json_ld_header do
%{
"@context" => [
def update_element_in_object(property, element, object) do
with new_data <-
- object.data |> Map.put("#{property}_count", length(element))
+ object.data
+ |> Map.put("#{property}_count", length(element))
|> Map.put("#{property}s", element),
changeset <- Changeset.change(object, data: new_data),
{:ok, object} <- Repo.update(changeset),
"""
def make_unannounce_data(
%User{ap_id: ap_id} = user,
- %Activity{data: %{"id" => id, "context" => context}} = activity
+ %Activity{data: %{"context" => context}} = activity,
+ activity_id
) do
- %{
+ data = %{
"type" => "Undo",
"actor" => ap_id,
- "object" => id,
+ "object" => activity.data,
"to" => [user.follower_address, activity.data["actor"]],
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
"context" => context
}
+
+ if activity_id, do: Map.put(data, "id", activity_id), else: data
+ end
+
+ def make_unlike_data(
+ %User{ap_id: ap_id} = user,
+ %Activity{data: %{"context" => context}} = activity,
+ activity_id
+ ) do
+ data = %{
+ "type" => "Undo",
+ "actor" => ap_id,
+ "object" => activity.data,
+ "to" => [user.follower_address, activity.data["actor"]],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "context" => context
+ }
+
+ if activity_id, do: Map.put(data, "id", activity_id), else: data
end
def add_announce_to_object(%Activity{data: %{"actor" => actor}}, object) do