Get create activity from created object id.

This is useful for Ostatus federation because ostatus doesn't have
different ids for objects and activities...
This commit is contained in:
Roger Braun 2017-04-30 11:16:41 +02:00
parent 11ea08649d
commit 9d7c3190cc
3 changed files with 13 additions and 1 deletions

View File

@ -18,4 +18,9 @@ defmodule Pleroma.Activity do
Repo.all(from activity in Activity, Repo.all(from activity in Activity,
where: fragment("? @> ?", activity.data, ^%{object: %{id: ap_id}})) where: fragment("? @> ?", activity.data, ^%{object: %{id: ap_id}}))
end 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 end

View File

@ -15,4 +15,11 @@ defmodule Pleroma.ActivityTest do
assert activity == found_activity assert activity == found_activity
end 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 end

View File

@ -22,7 +22,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
|> :xmerl.export_simple_content(:xmerl_xml) |> :xmerl.export_simple_content(:xmerl_xml)
expected = """ 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> <id>#{OStatus.feed_path(user)}</id>
<title>#{user.nickname}'s timeline</title> <title>#{user.nickname}'s timeline</title>
<updated>#{most_recent_update}</updated> <updated>#{most_recent_update}</updated>