Pull in remote avatar on federation.
[akkoma] / lib / pleroma / user.ex
index 3ce07d510b433eb1a699273dbe0f8990a4caaf0b..cd61046802bfbfcbe1bfaaa0b936b87b04012d24 100644 (file)
@@ -15,6 +15,8 @@ defmodule Pleroma.User do
     field :following, { :array, :string }, default: []
     field :ap_id, :string
     field :avatar, :map
+    field :local, :boolean, default: true
+    field :info, :map
 
     timestamps()
   end
@@ -63,6 +65,7 @@ defmodule Pleroma.User do
     |> validate_confirmation(:password)
     |> unique_constraint(:email)
     |> unique_constraint(:nickname)
+    |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
 
     if changeset.valid? do
       hashed = Comeonin.Pbkdf2.hashpwsalt(changeset.changes[:password])
@@ -119,4 +122,9 @@ defmodule Pleroma.User do
     key = "nickname:#{nickname}"
     Cachex.get!(:user_cache, key, fallback: fn(_) -> Repo.get_by(User, nickname: nickname) end)
   end
+
+  def get_cached_user_info(user) do
+    key = "user_info:#{user.id}"
+    Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end)
+  end
 end