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

@ -1,6 +1,7 @@
defmodule Pleroma.User do
use Ecto.Schema
alias Pleroma.User
import Ecto.Changeset
alias Pleroma.{Repo, User}
schema "users" do
field :bio, :string
@ -26,4 +27,20 @@ defmodule Pleroma.User do
def ap_followers(%User{} = user) do
"#{ap_id(user)}/followers"
end
def follow_changeset(struct, params \\ %{}) do
struct
|> cast(params, [:following])
|> validate_required([:following])
end
def follow(%User{} = follower, %User{} = followed) do
ap_followers = User.ap_followers(followed)
following = [ap_followers | follower.following]
|> Enum.uniq
follower
|> follow_changeset(%{following: following})
|> Repo.update
end
end