handle already following better, cache actor query
This commit is contained in:
parent
03c8d936fa
commit
d7ad3da610
|
@ -59,7 +59,7 @@ defmodule Vonbraun.Control do
|
|||
{:error, {:post, error}}
|
||||
end
|
||||
else
|
||||
{:pending, {:ok, %{:blocks_me => nil, :following_state => "accepted"}}} ->
|
||||
{:pending, {:error, :already_following}} ->
|
||||
Logger.info("I think you already follow them.")
|
||||
:ok
|
||||
|
||||
|
|
|
@ -104,6 +104,8 @@ defmodule Vonbraun.Ecto.Schema.Actor do
|
|||
with {:actor,
|
||||
{:ok, actor = %{:blocked => blocked?, :following_state => existing_following_state}}} <-
|
||||
{:actor, maybe_insert(id)} do
|
||||
already_following? = existing_following_state == "accepted" && new_state == "pending"
|
||||
|
||||
valid_set_pending? = existing_following_state == nil && new_state == "pending"
|
||||
|
||||
valid_set_response? =
|
||||
|
@ -120,6 +122,9 @@ defmodule Vonbraun.Ecto.Schema.Actor do
|
|||
changeset(actor, %{following_state: new_state, following_ts: DateTime.now!("Etc/UTC")})
|
||||
|> Repo.update()
|
||||
|
||||
already_following? ->
|
||||
{:error, :already_following}
|
||||
|
||||
true ->
|
||||
{:error, :invalid_state}
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue