Add id to objects, too.
This commit is contained in:
parent
1f0f79d959
commit
74112ef99e
2 changed files with 26 additions and 0 deletions
|
@ -6,6 +6,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
def insert(map) when is_map(map) do
|
def insert(map) when is_map(map) do
|
||||||
map = Map.put_new_lazy(map, "id", &generate_activity_id/0)
|
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})
|
Repo.insert(%Activity{data: map})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,6 +24,14 @@ def generate_activity_id do
|
||||||
"https://#{host}/activities/#{Ecto.UUID.generate}"
|
"https://#{host}/activities/#{Ecto.UUID.generate}"
|
||||||
end
|
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
|
def fetch_public_activities(opts \\ %{}) do
|
||||||
public = ["https://www.w3.org/ns/activitystreams#Public"]
|
public = ["https://www.w3.org/ns/activitystreams#Public"]
|
||||||
fetch_activities(public, opts)
|
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["ok"] == data["ok"]
|
||||||
assert activity.data["id"] == given_id
|
assert activity.data["id"] == given_id
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "fetch activities for recipients" do
|
describe "fetch activities for recipients" do
|
||||||
|
|
Loading…
Reference in a new issue