Add following TwAPI endpoint.

This commit is contained in:
Roger Braun 2017-03-22 18:36:08 +01:00
commit 75e51b190d
7 changed files with 78 additions and 1 deletions

View file

@ -34,6 +34,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|> activities_to_statuses
end
def follow(%User{} = follower, followed_id) do
with %User{} = followed <- Repo.get(User, followed_id),
{ :ok, follower } <- User.follow(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

@ -32,6 +32,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|> json_reply(200, json)
end
def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
{ :ok, _user, follower } = TwitterAPI.follow(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")