From 1f9a5272e18ecd90f23442ae0325b2e9fc3d1d96 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 4 Sep 2017 20:48:14 +0200 Subject: [PATCH] Add delete to TwAPI. --- lib/pleroma/web/router.ex | 1 + .../web/twitter_api/twitter_api_controller.ex | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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 @@ def user_fetcher(username) 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 @@ def follow(%{assigns: %{user: user}} = conn, params) 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} ->