def insert(map) when is_map(map) do
map = Map.put_new_lazy(map, "id", &generate_activity_id/0)
+ map = if map["object"] do
+ object = Map.put_new_lazy(map["object"], "id", &generate_object_id/0)
+ Map.put(map, "object", object)
+ else
+ map
+ end
+
Repo.insert(%Activity{data: map})
end
"https://#{host}/activities/#{Ecto.UUID.generate}"
end
+ def generate_object_id do
+ host =
+ Application.get_env(:pleroma, Pleroma.Web.Endpoint)
+ |> Keyword.fetch!(:url)
+ |> Keyword.fetch!(:host)
+ "https://#{host}/objects/#{Ecto.UUID.generate}"
+ end
+
def fetch_public_activities(opts \\ %{}) do
public = ["https://www.w3.org/ns/activitystreams#Public"]
fetch_activities(public, opts)
assert activity.data["ok"] == data["ok"]
assert activity.data["id"] == given_id
end
+
+ test "adds an id to a given object if it lacks one" do
+ data = %{
+ "object" => %{
+ "ok" => true
+ }
+ }
+
+ {:ok, %Activity{} = activity} = ActivityPub.insert(data)
+ assert is_binary(activity.data["object"]["id"])
+ end
end
describe "fetch activities for recipients" do