96 lines
2.1 KiB
Elixir
96 lines
2.1 KiB
Elixir
defmodule Nulla.Actors.Actor do
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
alias Nulla.Snowflake
|
|
|
|
@primary_key {:id, :integer, autogenerate: false}
|
|
schema "actors" do
|
|
field :acct, :string
|
|
field :ap_id, :string
|
|
field :type, :string
|
|
field :following, :string
|
|
field :followers, :string
|
|
field :inbox, :string
|
|
field :outbox, :string
|
|
field :featured, :string
|
|
field :featuredTags, :string
|
|
field :preferredUsername, :string
|
|
field :name, :string
|
|
field :summary, :string
|
|
field :url, :string
|
|
field :manuallyApprovesFollowers, :boolean, default: false
|
|
field :discoverable, :boolean, default: true
|
|
field :indexable, :boolean, default: true
|
|
field :published, :utc_datetime
|
|
field :memorial, :boolean, default: false
|
|
field :publicKey, :map
|
|
field :privateKeyPem, :string
|
|
field :tag, {:array, :map}, default: []
|
|
field :attachment, {:array, :map}, default: []
|
|
field :endpoints, :map
|
|
field :icon, :map
|
|
field :image, :map
|
|
field :vcard_bday, :date
|
|
field :vcard_Address, :string
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
@doc false
|
|
def changeset(actor, attrs) do
|
|
actor
|
|
|> cast(attrs, [
|
|
:acct,
|
|
:ap_id,
|
|
:type,
|
|
:following,
|
|
:followers,
|
|
:inbox,
|
|
:outbox,
|
|
:featured,
|
|
:featuredTags,
|
|
:preferredUsername,
|
|
:name,
|
|
:summary,
|
|
:url,
|
|
:manuallyApprovesFollowers,
|
|
:discoverable,
|
|
:indexable,
|
|
:published,
|
|
:memorial,
|
|
:publicKey,
|
|
:privateKeyPem,
|
|
:tag,
|
|
:attachment,
|
|
:endpoints,
|
|
:icon,
|
|
:image,
|
|
:vcard_bday,
|
|
:vcard_Address
|
|
])
|
|
|> maybe_put_id()
|
|
|> validate_required([
|
|
:acct,
|
|
:ap_id,
|
|
:type,
|
|
:following,
|
|
:followers,
|
|
:inbox,
|
|
:outbox,
|
|
:preferredUsername,
|
|
:url,
|
|
:publicKey,
|
|
:endpoints
|
|
])
|
|
end
|
|
|
|
defp maybe_put_id(changeset) do
|
|
id_in_attrs = get_field(changeset, :id)
|
|
|
|
if is_nil(id_in_attrs) do
|
|
change(changeset, id: Snowflake.next_id())
|
|
else
|
|
changeset
|
|
end
|
|
end
|
|
end
|