fix up missing announcements with preloads
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 25 Mar 2019 03:32:19 +0000 (03:32 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 25 Mar 2019 07:38:09 +0000 (07:38 +0000)
lib/pleroma/activity.ex
test/web/activity_pub/activity_pub_test.exs

index 26190df2fabac32305e5fba728eadc6e844bbf66..3dfabe9f35a7926ac7671006e19c0021876c1ac3 100644 (file)
@@ -41,8 +41,8 @@ defmodule Pleroma.Activity do
     #
     # ```
     # |> join(:inner, [activity], o in Object,
-    #      on: fragment("(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
-    #        o.data, activity.data))
+    #      on: fragment("(?->>'id') = COALESCE((?)->'object'->> 'id', (?)->>'object')",
+    #        o.data, activity.data, activity.data))
     # |> preload([activity, object], [object: object])
     # ```
     #
@@ -61,8 +61,9 @@ defmodule Pleroma.Activity do
       o in Object,
       on:
         fragment(
-          "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
+          "(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
           o.data,
+          activity.data,
           activity.data
         )
     )
@@ -86,8 +87,9 @@ defmodule Pleroma.Activity do
         left_join: o in Object,
         on:
           fragment(
-            "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
+            "(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
             o.data,
+            activity.data,
             activity.data
           ),
         preload: [object: o]
@@ -105,8 +107,9 @@ defmodule Pleroma.Activity do
       inner_join: o in Object,
       on:
         fragment(
-          "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
+          "(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
           o.data,
+          activity.data,
           activity.data
         ),
       preload: [object: o]
@@ -182,8 +185,9 @@ defmodule Pleroma.Activity do
       inner_join: o in Object,
       on:
         fragment(
-          "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
+          "(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
           o.data,
+          activity.data,
           activity.data
         ),
       preload: [object: o]
index c8c3b6d5fa8081427e8fa45e67f7a5a4e6420f28..96ad64e62685e32e97a3534c7ba9e45c2391fcc7 100644 (file)
@@ -365,6 +365,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     assert Enum.member?(activities, activity_one)
   end
 
+  test "does include announces on request" do
+    activity_three = insert(:note_activity)
+    user = insert(:user)
+    booster = insert(:user)
+
+    {:ok, user} = User.follow(user, booster)
+
+    {:ok, announce, _object} = CommonAPI.repeat(activity_three.id, booster)
+
+    [announce_activity] = ActivityPub.fetch_activities([user.ap_id | user.following])
+
+    assert announce_activity.id == announce.id
+  end
+
   test "excludes reblogs on request" do
     user = insert(:user)
     {:ok, expected_activity} = ActivityBuilder.insert(%{"type" => "Create"}, %{:user => user})