blocking functions

This commit is contained in:
Moon Man 2024-08-24 19:26:45 +00:00
parent a9e15e7515
commit d19a228dca
1 changed files with 39 additions and 0 deletions

View File

@ -8,6 +8,7 @@ defmodule Vonbraun.Ecto.Schema.Actor do
schema "actors" do
field(:muted, :boolean)
field(:blocked, :naive_datetime)
field(:blocks_me, :naive_datetime)
field(:follows_me_state, :string)
field(:follows_me_ts, :naive_datetime)
field(:following_state, :string)
@ -126,4 +127,42 @@ defmodule Vonbraun.Ecto.Schema.Actor do
{:error, error}
end
end
@spec block(String.t()) :: {:ok, __MODULE__.t()} | {:error, Changeset.t()}
def block(id) when is_binary(id) do
with {:actor, {:ok, actor}} <- {:actor, maybe_insert(id)} do
now = DateTime.now!("Etc/UTC")
changeset(actor, %{
blocked: now,
follows_me_state: nil,
follows_me_ts: now,
following_state: nil,
following_ts: now
})
|> Repo.update()
else
{:actor, {:error, error}} ->
{:error, error}
end
end
@spec block_me(String.t()) :: {:ok, __MODULE__.t()} | {:error, Changeset.t()}
def block_me(id) when is_binary(id) do
with {:actor, {:ok, actor}} <- {:actor, maybe_insert(id)} do
now = DateTime.now!("Etc/UTC")
changeset(actor, %{
blocks_me: now,
follows_me_state: nil,
follows_me_ts: now,
following_state: nil,
following_ts: now
})
|> Repo.update()
else
{:actor, {:error, error}} ->
{:error, error}
end
end
end