forked from AkkomaGang/akkoma
Mark incoming activties as non-local.
This commit is contained in:
parent
56bacc90d1
commit
6dd8335477
3 changed files with 6 additions and 5 deletions
|
@ -3,7 +3,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
alias Pleroma.{Activity, Object, Upload, User}
|
alias Pleroma.{Activity, Object, Upload, User}
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def insert(map) when is_map(map) do
|
def insert(map, local \\ true) when is_map(map) do
|
||||||
map = map
|
map = map
|
||||||
|> Map.put_new_lazy("id", &generate_activity_id/0)
|
|> Map.put_new_lazy("id", &generate_activity_id/0)
|
||||||
|> Map.put_new_lazy("published", &make_date/0)
|
|> Map.put_new_lazy("published", &make_date/0)
|
||||||
|
@ -16,10 +16,10 @@ def insert(map) when is_map(map) do
|
||||||
map
|
map
|
||||||
end
|
end
|
||||||
|
|
||||||
Repo.insert(%Activity{data: map})
|
Repo.insert(%Activity{data: map, local: local})
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(to, actor, context, object, additional \\ %{}, published \\ nil) do
|
def create(to, actor, context, object, additional \\ %{}, published \\ nil, local \\ true) do
|
||||||
published = published || make_date()
|
published = published || make_date()
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
|
@ -32,7 +32,7 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil) do
|
||||||
}
|
}
|
||||||
|> Map.merge(additional)
|
|> Map.merge(additional)
|
||||||
|
|
||||||
with {:ok, activity} <- insert(activity) do
|
with {:ok, activity} <- insert(activity, local) do
|
||||||
if actor.local do
|
if actor.local do
|
||||||
Pleroma.Web.Federator.enqueue(:publish, activity)
|
Pleroma.Web.Federator.enqueue(:publish, activity)
|
||||||
end
|
end
|
||||||
|
|
|
@ -86,7 +86,7 @@ def handle_note(entry, doc \\ nil) do
|
||||||
if Object.get_by_ap_id(id) do
|
if Object.get_by_ap_id(id) do
|
||||||
{:error, "duplicate activity"}
|
{:error, "duplicate activity"}
|
||||||
else
|
else
|
||||||
ActivityPub.create(to, actor, context, object, %{}, date)
|
ActivityPub.create(to, actor, context, object, %{}, date, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ test "handle incoming note - GS, Salmon" do
|
||||||
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
|
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
|
||||||
assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
|
assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
|
||||||
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
|
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
|
||||||
|
assert activity.local == false
|
||||||
end
|
end
|
||||||
|
|
||||||
test "handle incoming notes - GS, subscription" do
|
test "handle incoming notes - GS, subscription" do
|
||||||
|
|
Loading…
Reference in a new issue