Add delete to TwAPI.

This commit is contained in:
Roger Braun 2017-09-04 20:48:14 +02:00
parent 3438a120cc
commit 1f9a5272e1
2 changed files with 13 additions and 1 deletions

View file

@ -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

View file

@ -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} ->