Get create activity from created object id.
authorRoger Braun <roger@rogerbraun.net>
Sun, 30 Apr 2017 09:16:41 +0000 (11:16 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 30 Apr 2017 09:16:41 +0000 (11:16 +0200)
This is useful for Ostatus federation because ostatus doesn't have
different ids for objects and activities...

lib/pleroma/activity.ex
test/activity_test.exs
test/web/ostatus/feed_representer_test.exs

index 46568bb13eb288d6322b145db776e5427aa5e9c8..80d96d0f20bc0e765e05131833a24c712b9adace 100644 (file)
@@ -18,4 +18,9 @@ defmodule Pleroma.Activity 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
index ce6eb15451f7ad7ba6b126d41a9d034b007532ae..366a2f9572290d139e81cd2563b4d1e42ee4f1ec 100644 (file)
@@ -15,4 +15,11 @@ defmodule Pleroma.ActivityTest 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
index ef0f4d5fffe3a50ff27e79afdd477b3893c9b30c..7bbfae49a3a62ba5cfd9c555b8ff94fae7d89051 100644 (file)
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
     |> :xmerl.export_simple_content(:xmerl_xml)
 
     expected = """
-    <feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
+    <feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
       <id>#{OStatus.feed_path(user)}</id>
       <title>#{user.nickname}'s timeline</title>
       <updated>#{most_recent_update}</updated>