diff options
Diffstat (limited to 'lib/pleroma/web/twitter_api')
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api.ex | 8 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api_controller.ex | 10 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index fb093b227..2ef679397 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -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"]) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index ac319b109..d574f1003 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -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") |