Refactor code to comply with credo suggestions
This commit is contained in:
parent
fb5cebc1b5
commit
6cf7c13228
21 changed files with 318 additions and 157 deletions
|
|
@ -1,8 +1,8 @@
|
|||
defmodule Pleroma.User do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
alias Pleroma.{Repo, User, Activity, Object}
|
||||
import Ecto.{Changeset, Query}
|
||||
alias Pleroma.{Repo, User, Object, Web}
|
||||
alias Comeonin.Pbkdf2
|
||||
|
||||
schema "users" do
|
||||
field :bio, :string
|
||||
|
|
@ -12,7 +12,7 @@ defmodule Pleroma.User do
|
|||
field :password_hash, :string
|
||||
field :password, :string, virtual: true
|
||||
field :password_confirmation, :string, virtual: true
|
||||
field :following, { :array, :string }, default: []
|
||||
field :following, {:array, :string}, default: []
|
||||
field :ap_id, :string
|
||||
field :avatar, :map
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ defmodule Pleroma.User do
|
|||
end
|
||||
|
||||
def ap_id(%User{nickname: nickname}) do
|
||||
"#{Pleroma.Web.base_url}/users/#{nickname}"
|
||||
"#{Web.base_url}/users/#{nickname}"
|
||||
end
|
||||
|
||||
def ap_followers(%User{} = user) do
|
||||
|
|
@ -66,7 +66,7 @@ defmodule Pleroma.User do
|
|||
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|
||||
|
||||
if changeset.valid? do
|
||||
hashed = Comeonin.Pbkdf2.hashpwsalt(changeset.changes[:password])
|
||||
hashed = Pbkdf2.hashpwsalt(changeset.changes[:password])
|
||||
ap_id = User.ap_id(%User{nickname: changeset.changes[:nickname]})
|
||||
followers = User.ap_followers(%User{nickname: changeset.changes[:nickname]})
|
||||
changeset
|
||||
|
|
@ -81,8 +81,8 @@ defmodule Pleroma.User do
|
|||
def follow(%User{} = follower, %User{} = followed) do
|
||||
ap_followers = User.ap_followers(followed)
|
||||
if following?(follower, followed) do
|
||||
{ :error,
|
||||
"Could not follow user: #{followed.nickname} is already on your list." }
|
||||
{:error,
|
||||
"Could not follow user: #{followed.nickname} is already on your list."}
|
||||
else
|
||||
following = [ap_followers | follower.following]
|
||||
|> Enum.uniq
|
||||
|
|
@ -103,7 +103,7 @@ defmodule Pleroma.User do
|
|||
|> follow_changeset(%{following: following})
|
||||
|> Repo.update
|
||||
else
|
||||
{ :error, "Not subscribed!" }
|
||||
{:error, "Not subscribed!"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue