Add unfollowing to TwAPI.

This commit is contained in:
Roger Braun 2017-03-23 13:13:09 +01:00
commit 30650e5bc6
7 changed files with 75 additions and 1 deletions

View file

@ -42,6 +42,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
end
end
def unfollow(%User{} = follower, followed_id) do
with %User{} = followed <- Repo.get(User, followed_id),
{ :ok, follower } <- User.unfollow(follower, followed)
do
{ :ok, follower, followed }
end
end
defp activities_to_statuses(activities) do
Enum.map(activities, fn(activity) ->
actor = get_in(activity.data, ["actor"])

View file

@ -41,6 +41,16 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|> json_reply(200, response)
end
def unfollow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
{ :ok, _user, follower } = TwitterAPI.unfollow(user, followed_id)
response = follower |> UserRepresenter.to_json
conn
|> json_reply(200, response)
end
defp json_reply(conn, status, json) do
conn
|> put_resp_content_type("application/json")