From: Roger Braun Date: Mon, 4 Sep 2017 18:48:14 +0000 (+0200) Subject: Add delete to TwAPI. X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;h=1f9a5272e18ecd90f23442ae0325b2e9fc3d1d96;p=akkoma Add delete to TwAPI. --- diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 2b22140ee..c20ec3e80 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -82,6 +82,7 @@ defmodule Pleroma.Web.Router do post "/statuses/update", TwitterAPI.Controller, :status_update post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet + post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post post "/friendships/create", TwitterAPI.Controller, :follow post "/friendships/destroy", TwitterAPI.Controller, :unfollow diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 3580e48d2..3ec54616a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -2,7 +2,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do use Pleroma.Web, :controller alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter - alias Pleroma.{Repo, Activity, User} + alias Pleroma.{Repo, Activity, User, Object} alias Pleroma.Web.ActivityPub.ActivityPub alias Ecto.Changeset @@ -94,6 +94,17 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def delete_post(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, id), + %Object{} = object <- Object.get_by_ap_id(object_id), + true <- user.ap_id == object.data["actor"], + {:ok, delete} <- ActivityPub.delete(object) |> IO.inspect do + json = ActivityRepresenter.to_json(delete, %{user: user, for: user}) + conn + |> json_reply(200, json) + end + end + def unfollow(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.unfollow(user, params) do {:ok, user, unfollowed} ->