From 6dd8335477ff3adc2dda5fe4e45b0e1b38dc5b9b Mon Sep 17 00:00:00 2001
From: Roger Braun <roger@rogerbraun.net>
Date: Tue, 2 May 2017 10:47:04 +0200
Subject: [PATCH] Mark incoming activties as non-local.

---
 lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++----
 lib/pleroma/web/ostatus/ostatus.ex           | 2 +-
 test/web/ostatus/ostatus_test.exs            | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 9441a37ab..4eab2e2d0 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -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
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index 6a6f43acf..db32d2c35 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -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
 
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 4e7e401cd..3951dbc9c 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -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