2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.Actors.Bot do
|
2018-05-30 14:27:21 +02:00
|
|
|
@moduledoc """
|
2019-09-09 00:52:49 +02:00
|
|
|
Represents a local bot.
|
2018-05-30 14:27:21 +02:00
|
|
|
"""
|
2019-09-09 00:52:49 +02:00
|
|
|
|
2018-05-30 14:27:21 +02:00
|
|
|
use Ecto.Schema
|
2019-09-09 00:52:49 +02:00
|
|
|
|
2018-05-30 14:27:21 +02:00
|
|
|
import Ecto.Changeset
|
2019-09-09 00:52:49 +02:00
|
|
|
|
2019-03-05 17:23:05 +01:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Users.User
|
2018-05-30 14:27:21 +02:00
|
|
|
|
2019-09-09 00:52:49 +02:00
|
|
|
@type t :: %__MODULE__{
|
|
|
|
source: String.t(),
|
|
|
|
type: String.t(),
|
|
|
|
actor: Actor.t(),
|
|
|
|
user: User.t()
|
|
|
|
}
|
|
|
|
|
|
|
|
@required_attrs [:source]
|
|
|
|
@optional_attrs [:type, :actor_id, :user_id]
|
|
|
|
@attrs @required_attrs ++ @optional_attrs
|
|
|
|
|
2018-05-30 14:27:21 +02:00
|
|
|
schema "bots" do
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:source, :string)
|
2021-04-08 10:04:06 +02:00
|
|
|
field(:type, :string, default: "ics")
|
2019-09-09 00:52:49 +02:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
belongs_to(:actor, Actor)
|
|
|
|
belongs_to(:user, User)
|
2018-05-30 14:27:21 +02:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
|
2019-09-13 01:55:45 +02:00
|
|
|
def changeset(%__MODULE__{} = bot, attrs) do
|
2018-05-30 14:27:21 +02:00
|
|
|
bot
|
2019-09-09 00:52:49 +02:00
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_required(@required_attrs)
|
2018-05-30 14:27:21 +02:00
|
|
|
end
|
|
|
|
end
|