From 26b0c802c3eece72928d0425826af9fe728a5173 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 25 Mar 2019 03:32:19 +0000 Subject: [PATCH] fix up missing announcements with preloads --- lib/pleroma/activity.ex | 16 ++++++++++------ test/web/activity_pub/activity_pub_test.exs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 26190df2f..3dfabe9f3 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -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 @@ def with_preloaded_object(query) 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 @@ def get_by_ap_id_with_object(ap_id) 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 @@ def get_by_id_with_object(id) 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 @@ def create_by_object_ap_id_with_object(ap_id) when is_binary(ap_id) 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] diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index c8c3b6d5f..96ad64e62 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -365,6 +365,20 @@ test "doesn't return muted activities" 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})