diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-09-09 17:48:57 +0200 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-09-09 17:48:57 +0200 |
commit | 66e4c710d469d7f2177c06e0dafb181d4d4abf30 (patch) | |
tree | 38dd73db9163d61518016d8ebc790c3dfd92b1b8 /lib/pleroma/web/common_api/common_api.ex | |
parent | 4dc517a0bb979793c1c2590d38efe853c68eb80c (diff) | |
download | pleroma-66e4c710d469d7f2177c06e0dafb181d4d4abf30.tar.gz |
Add reblogging to MastodonAPI.
Diffstat (limited to 'lib/pleroma/web/common_api/common_api.ex')
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index a894ac9c1..b1d2172c7 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -10,4 +10,25 @@ defmodule Pleroma.Web.CommonAPI do {:ok, delete} end end + + def repeat(id_or_ap_id, user) do + with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), + false <- activity.data["actor"] == user.ap_id, + object <- Object.get_by_ap_id(activity.data["object"]["id"]) do + ActivityPub.announce(user, object) + else + _ -> + {:error, "Could not repeat"} + end + end + + # This is a hack for twidere. + def get_by_id_or_ap_id(id) do + activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id) + if activity.data["type"] == "Create" do + activity + else + Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + end + end end |