From 9d7c3190cc346bf2a5576b6b93c26723059ae9a1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 30 Apr 2017 11:16:41 +0200 Subject: [PATCH] Get create activity from created object id. This is useful for Ostatus federation because ostatus doesn't have different ids for objects and activities... --- lib/pleroma/activity.ex | 5 +++++ test/activity_test.exs | 7 +++++++ test/web/ostatus/feed_representer_test.exs | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 46568bb13..80d96d0f2 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -18,4 +18,9 @@ def all_by_object_ap_id(ap_id) do Repo.all(from activity in Activity, where: fragment("? @> ?", activity.data, ^%{object: %{id: ap_id}})) end + + def get_create_activity_by_object_ap_id(ap_id) do + Repo.one(from activity in Activity, + where: fragment("? @> ?", activity.data, ^%{type: "Create", object: %{id: ap_id}})) + end end diff --git a/test/activity_test.exs b/test/activity_test.exs index ce6eb1545..366a2f957 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -15,4 +15,11 @@ test "returns activities by it's objects AP ids" do assert activity == found_activity end + + test "returns the activity that created an object" do + activity = insert(:note_activity) + found_activity = Pleroma.Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"]) + + assert activity == found_activity + end end diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs index ef0f4d5ff..7bbfae49a 100644 --- a/test/web/ostatus/feed_representer_test.exs +++ b/test/web/ostatus/feed_representer_test.exs @@ -22,7 +22,7 @@ test "returns a feed of the last 20 items of the user" do |> :xmerl.export_simple_content(:xmerl_xml) expected = """ - + #{OStatus.feed_path(user)} #{user.nickname}'s timeline #{most_recent_update}