Commit 1f0f79d9 authored by lain's avatar lain
Browse files

Generate ids for activities.

parent 9ad045fd
......@@ -4,9 +4,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
import Ecto.Query
def insert(map) when is_map(map) do
map = Map.put_new_lazy(map, "id", &generate_activity_id/0)
Repo.insert(%Activity{data: map})
end
def generate_activity_id do
host =
Application.get_env(:pleroma, Pleroma.Web.Endpoint)
|> Keyword.fetch!(:url)
|> Keyword.fetch!(:host)
"https://#{host}/activities/#{Ecto.UUID.generate}"
end
def fetch_public_activities(opts \\ %{}) do
public = ["https://www.w3.org/ns/activitystreams#Public"]
fetch_activities(public, opts)
......
......@@ -5,17 +5,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Builders.ActivityBuilder
describe "insertion" do
test "inserts a given map into the activity database" do
test "inserts a given map into the activity database, giving it an id if it has none." do
data = %{
ok: true
"ok" => true
}
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
assert activity.data == data
assert activity.data["ok"] == data["ok"]
assert is_binary(activity.data["id"])
given_id = "bla"
data = %{
"ok" => true,
"id" => given_id
}
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
assert activity.data["ok"] == data["ok"]
assert activity.data["id"] == given_id
end
end
describe "fetch activities for recipients" do
test "retrieve the activities for certain recipients" do
{:ok, activity_one} = ActivityBuilder.insert(%{"to" => ["someone"]})
......
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