Mark incoming activties as non-local.

This commit is contained in:
Roger Braun 2017-05-02 10:47:04 +02:00
parent 56bacc90d1
commit 6dd8335477
3 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.{Activity, Object, Upload, User}
import Ecto.Query
def insert(map) when is_map(map) do
def insert(map, local \\ true) when is_map(map) do
map = map
|> Map.put_new_lazy("id", &generate_activity_id/0)
|> Map.put_new_lazy("published", &make_date/0)
@ -16,10 +16,10 @@ def insert(map) when is_map(map) do
map
end
Repo.insert(%Activity{data: map})
Repo.insert(%Activity{data: map, local: local})
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()
activity = %{
@ -32,7 +32,7 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil) do
}
|> Map.merge(additional)
with {:ok, activity} <- insert(activity) do
with {:ok, activity} <- insert(activity, local) do
if actor.local do
Pleroma.Web.Federator.enqueue(:publish, activity)
end

View File

@ -86,7 +86,7 @@ def handle_note(entry, doc \\ nil) do
if Object.get_by_ap_id(id) do
{:error, "duplicate activity"}
else
ActivityPub.create(to, actor, context, object, %{}, date)
ActivityPub.create(to, actor, context, object, %{}, date, false)
end
end

View File

@ -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["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 activity.local == false
end
test "handle incoming notes - GS, subscription" do