Mark incoming activties as non-local.
authorRoger Braun <roger@rogerbraun.net>
Tue, 2 May 2017 08:47:04 +0000 (10:47 +0200)
committerRoger Braun <roger@rogerbraun.net>
Tue, 2 May 2017 08:47:04 +0000 (10:47 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/ostatus/ostatus.ex
test/web/ostatus/ostatus_test.exs

index 9441a37aba9b263b51a88176ff64590391fe00b7..4eab2e2d040aa1d60a5bb3e07b2aaf17fbdf9486 100644 (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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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
index 6a6f43acf212df65233044b247233696ea38d5f8..db32d2c354b63e668e97ae3e8eaaa22aeec92bf1 100644 (file)
@@ -86,7 +86,7 @@ defmodule Pleroma.Web.OStatus 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
 
index 4e7e401cde3c761c1f349d56cebf92e8c26b4630..3951dbc9cd72328bc042145bf3dfe4c57267ab3a 100644 (file)
@@ -18,6 +18,7 @@ defmodule Pleroma.Web.OStatusTest 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