X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fuser.ex;h=39d8cca768aeb7222b654de3d119fbf2ba409683;hb=c36229c4aa3bd0ac49d9dcd589790f5c47470564;hp=f28f0deb0cad55c2b418f444cef94b28522f77e3;hpb=72ca58c540ee03de50631ea08a419f2589a0fe8e;p=akkoma diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f28f0deb0..39d8cca76 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -2,7 +2,7 @@ defmodule Pleroma.User do use Ecto.Schema import Ecto.{Changeset, Query} - alias Pleroma.{Repo, User, Object, Web} + alias Pleroma.{Repo, User, Object, Web, Activity, Notification} alias Comeonin.Pbkdf2 alias Pleroma.Web.{OStatus, Websub} alias Pleroma.Web.ActivityPub.ActivityPub @@ -22,6 +22,7 @@ defmodule Pleroma.User do field :local, :boolean, default: true field :info, :map, default: %{} field :follower_address, :string + has_many :notifications, Notification timestamps() end @@ -80,6 +81,15 @@ defmodule Pleroma.User do end end + def update_changeset(struct, params \\ %{}) do + changeset = struct + |> cast(params, [:bio, :name]) + |> unique_constraint(:nickname) + |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) + |> validate_length(:bio, min: 1, max: 1000) + |> validate_length(:name, min: 1, max: 100) + end + def register_changeset(struct, params \\ %{}) do changeset = struct |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation]) @@ -89,8 +99,8 @@ defmodule Pleroma.User do |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) |> validate_format(:email, @email_regex) - |> validate_length(:bio, max: 1000) - |> validate_length(:name, max: 100) + |> validate_length(:bio, min: 1, max: 1000) + |> validate_length(:name, min: 1, max: 100) if changeset.valid? do hashed = Pbkdf2.hashpwsalt(changeset.changes[:password]) @@ -230,4 +240,12 @@ defmodule Pleroma.User do Repo.update(cs) end + + def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) do + query = from u in User, + where: u.ap_id in ^to, + where: u.local == true + + Repo.all(query) + end end