Commit 74112ef9 authored by lain's avatar lain
Browse files

Add id to objects, too.

parent 1f0f79d9
......@@ -6,6 +6,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
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
......@@ -17,6 +24,14 @@ def generate_activity_id do
"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)
......
......@@ -24,6 +24,17 @@ test "inserts a given map into the activity database, giving it an id if it has
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
......
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