i'm learning

This commit is contained in:
Henry Jameson 2026-11-09 16:23:19 +02:00
commit 226135e2e1
2 changed files with 8 additions and 2 deletions

View file

@ -97,12 +97,18 @@ defmodule Pleroma.Web.OAuth.Token do
|> validate_required([:valid_until])
end
defp update_activity do
@spec update_activity(Token.t()) :: {:ok, Token.t()} | {:error, Ecto.Changeset.t()}
def update_activity(token) do
last_active = NaiveDateTime.utc_now()
changeset = Ecto.Changeset.change(token)
changeset
|> change(%{last_active: last_active})
|> validate_required([:last_active])
|> Repo.insert()
{: ok, token}
end
@spec create(App.t(), User.t(), map()) :: {:ok, Token.t()} | {:error, Ecto.Changeset.t()}

View file

@ -24,7 +24,7 @@ defmodule Pleroma.Web.Plugs.OAuthPlug do
with {:ok, token_str} <- fetch_token_str(conn) do
with {:ok, user, user_token} <- fetch_user_and_token(token_str),
false <- Token.expired?(user_token) do
Token.update_activity()
Token.update_activity(user_token)
conn
|> assign(:token, user_token)