Add following TwAPI endpoint.
This commit is contained in:
parent
e2e0cd75b7
commit
75e51b190d
7 changed files with 78 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue