Fix accessing outdated page of group

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-06-16 11:27:14 +02:00
parent a765d226b8
commit 725a3c8b9e
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 18 additions and 12 deletions

View File

@ -76,14 +76,19 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do
@doc """ @doc """
Find an actor in our local database or call WebFinger to find what's its AP ID is and then fetch it Find an actor in our local database or call WebFinger to find what's its AP ID is and then fetch it
""" """
@spec find_or_make_actor_from_nickname(String.t(), atom() | nil) :: tuple() @spec find_or_make_actor_from_nickname(String.t(), atom() | nil) ::
{:ok, Actor.t()} | {:error, any()}
def find_or_make_actor_from_nickname(nickname, type \\ nil) do def find_or_make_actor_from_nickname(nickname, type \\ nil) do
case Actors.get_actor_by_name(nickname, type) do case Actors.get_actor_by_name_with_preload(nickname, type) do
%Actor{} = actor -> %Actor{url: actor_url} = actor ->
{:ok, actor} if Actors.needs_update?(actor) do
make_actor_from_url(actor_url, true)
else
{:ok, actor}
end
nil -> nil ->
make_actor_from_nickname(nickname) make_actor_from_nickname(nickname, true)
end end
end end
@ -94,10 +99,10 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do
Create an actor inside our database from username, using WebFinger to find out its AP ID and then fetch it Create an actor inside our database from username, using WebFinger to find out its AP ID and then fetch it
""" """
@spec make_actor_from_nickname(String.t()) :: {:ok, %Actor{}} | {:error, any()} @spec make_actor_from_nickname(String.t()) :: {:ok, %Actor{}} | {:error, any()}
def make_actor_from_nickname(nickname) do def make_actor_from_nickname(nickname, preload \\ false) do
case WebFinger.finger(nickname) do case WebFinger.finger(nickname) do
{:ok, url} when is_binary(url) -> {:ok, url} when is_binary(url) ->
make_actor_from_url(url) make_actor_from_url(url, preload)
_e -> _e ->
{:error, "No ActivityPub URL found in WebFinger"} {:error, "No ActivityPub URL found in WebFinger"}

View File

@ -4,10 +4,11 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
""" """
alias Mobilizon.{Actors, Discussions, Events, Posts, Resources, Todos, Tombstone} alias Mobilizon.{Actors, Discussions, Events, Posts, Resources, Todos, Tombstone}
alias Mobilizon.Actors.{Actor, Member} alias Mobilizon.Actors.Actor, as: ActorModel
alias Mobilizon.Actors.Member
alias Mobilizon.Discussions.{Comment, Discussion} alias Mobilizon.Discussions.{Comment, Discussion}
alias Mobilizon.Events.Event alias Mobilizon.Events.Event
alias Mobilizon.Federation.ActivityPub.Relay alias Mobilizon.Federation.ActivityPub.{Actor, Relay}
alias Mobilizon.Posts.Post alias Mobilizon.Posts.Post
alias Mobilizon.Resources.Resource alias Mobilizon.Resources.Resource
alias Mobilizon.Todos.{Todo, TodoList} alias Mobilizon.Todos.{Todo, TodoList}
@ -23,8 +24,8 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
{:commit, Actor.t()} | {:ignore, nil} {:commit, Actor.t()} | {:ignore, nil}
def get_actor_by_name(name) do def get_actor_by_name(name) do
Cachex.fetch(@cache, "actor_" <> name, fn "actor_" <> name -> Cachex.fetch(@cache, "actor_" <> name, fn "actor_" <> name ->
case Actors.get_actor_by_name_with_preload(name) do case Actor.find_or_make_actor_from_nickname(name) do
%Actor{} = actor -> {:ok, %ActorModel{} = actor} ->
{:commit, actor} {:commit, actor}
nil -> nil ->
@ -41,7 +42,7 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
def get_local_actor_by_name(name) do def get_local_actor_by_name(name) do
Cachex.fetch(@cache, "local_actor_" <> name, fn "local_actor_" <> name -> Cachex.fetch(@cache, "local_actor_" <> name, fn "local_actor_" <> name ->
case Actors.get_local_actor_by_name(name) do case Actors.get_local_actor_by_name(name) do
%Actor{} = actor -> %ActorModel{} = actor ->
{:commit, actor} {:commit, actor}
nil -> nil ->