defmodule GitGud.Federation.Follow do
use Ecto.Schema
import Ecto.Changeset
alias GitGud.Federation.Activity
alias GitGud.Federation.Actor
schema "fed_follows" do
field :accepted_at, :utc_datetime
belongs_to :follower_actor, Actor
belongs_to :target_actor, Actor
belongs_to :follow_activity, Activity
timestamps(type: :utc_datetime)
end
def changeset(follow, attrs) do
follow
|> cast(attrs, [:follower_actor_id, :target_actor_id, :follow_activity_id, :accepted_at])
|> validate_required([:follower_actor_id, :target_actor_id])
|> unique_constraint(:follower_actor_id,
name: :fed_follows_follower_actor_id_target_actor_id_index
)
end
def accept(follow), do: change(follow, accepted_at: DateTime.utc_now(:second))
end
786 B · text
5af55d9