Redirect properly to correct endpoint depending on content-type

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-03-04 17:20:18 +01:00
parent 634157eb4b
commit 66e67aa816
12 changed files with 237 additions and 70 deletions

View File

@@ -378,6 +378,12 @@ defmodule Mobilizon.Actors.Actor do
end
end
def display_name_and_username(%Actor{name: nil} = actor), do: actor_acct_from_actor(actor)
def display_name_and_username(%Actor{name: ""} = actor), do: actor_acct_from_actor(actor)
def display_name_and_username(%Actor{name: name} = actor),
do: name <> " (" <> actor_acct_from_actor(actor) <> ")"
def clear_cache(%Actor{preferred_username: preferred_username, domain: nil}) do
Cachex.del(:activity_pub, "actor_" <> preferred_username)
end

View File

@@ -467,6 +467,20 @@ defmodule Mobilizon.Actors do
|> Repo.preload(:organized_events)
end
@doc """
Returns a cached local actor by username
"""
@spec get_cached_local_actor_by_name(String.t()) ::
{:ok, Actor.t()} | {:commit, Actor.t()} | {:ignore, any()}
def get_cached_local_actor_by_name(name) do
Cachex.fetch(:activity_pub, "actor_" <> name, fn "actor_" <> name ->
case get_local_actor_by_name(name) do
nil -> {:ignore, nil}
%Actor{} = actor -> {:commit, actor}
end
end)
end
@doc """
Getting an actor from url, eventually creating it
"""

View File

@@ -154,6 +154,16 @@ defmodule Mobilizon.Events do
|> Repo.one()
end
def get_cached_event_full_by_uuid(uuid) do
Cachex.fetch(:activity_pub, "event_" <> uuid, fn "event_" <> uuid ->
with %Event{} = event <- get_event_full_by_uuid(uuid) do
{:commit, event}
else
_ -> {:ignore, nil}
end
end)
end
@doc """
Gets a single event, with all associations loaded.
"""
@@ -1018,6 +1028,16 @@ defmodule Mobilizon.Events do
end
end
def get_cached_comment_full_by_uuid("comment_" <> uuid) do
Cachex.fetch(:activity_pub, "comment_" <> uuid, fn "comment_" <> uuid ->
with %Comment{} = comment <- Events.get_comment_full_from_uuid(uuid) do
{:commit, comment}
else
_ -> {:ignore, nil}
end
end)
end
def get_comment_from_url(url), do: Repo.get_by(Comment, url: url)
def get_comment_from_url!(url), do: Repo.get_by!(Comment, url: url)