Typespec fixes and refactoring
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -191,8 +191,8 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do
|
||||
defp process_collection(_, _), do: :error
|
||||
|
||||
# If we're handling an activity
|
||||
@spec handling_element(map()) :: {:ok, any, struct} | :error
|
||||
@spec handling_element(String.t()) :: {:ok, struct} | {:ok, atom, struct} | {:error, any()}
|
||||
@spec handling_element(map() | String.t()) ::
|
||||
{:ok, any, struct} | {:ok, struct} | {:ok, atom, struct} | {:error, any()} | :error
|
||||
defp handling_element(%{"type" => activity_type} = data)
|
||||
when activity_type in ["Create", "Update", "Delete"] do
|
||||
object = get_in(data, ["object"])
|
||||
|
||||
@@ -192,5 +192,5 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||
Map.put(res, "location", AddressConverter.model_to_as(physical_address))
|
||||
end
|
||||
|
||||
defp maybe_add_physical_address(res, %ActorModel{physical_address: _}), do: res
|
||||
defp maybe_add_physical_address(res, _), do: res
|
||||
end
|
||||
|
||||
@@ -48,12 +48,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Discussion do
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map) :: map() | {:error, atom()}
|
||||
def as_to_model_data(%{"type" => "Note", "name" => name} = object) when is_valid_string(name) do
|
||||
case extract_actors(object) do
|
||||
%{actor_id: actor_id, creator_id: creator_id} ->
|
||||
%{actor_id: actor_id, creator_id: creator_id, title: name, url: object["id"]}
|
||||
|
||||
{:error, error} ->
|
||||
{:error, error}
|
||||
with %{actor_id: actor_id, creator_id: creator_id} <- extract_actors(object) do
|
||||
%{actor_id: actor_id, creator_id: creator_id, title: name, url: object["id"]}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -46,22 +46,18 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Media do
|
||||
actor_id
|
||||
)
|
||||
when is_binary(media_url) do
|
||||
case upload_media(media_url, name) do
|
||||
{:error, err} ->
|
||||
{:error, err}
|
||||
with {:ok, %{url: url} = uploaded} <- upload_media(media_url, name) do
|
||||
case Medias.get_media_by_url(url) do
|
||||
%MediaModel{file: _file} = media ->
|
||||
{:ok, media}
|
||||
|
||||
{:ok, %{url: url} = uploaded} ->
|
||||
case Medias.get_media_by_url(url) do
|
||||
%MediaModel{file: _file} = media ->
|
||||
{:ok, media}
|
||||
|
||||
nil ->
|
||||
Medias.create_media(%{
|
||||
file: Map.take(uploaded, [:url, :name, :content_type, :size]),
|
||||
metadata: Map.take(uploaded, [:width, :height, :blurhash]),
|
||||
actor_id: actor_id
|
||||
})
|
||||
end
|
||||
nil ->
|
||||
Medias.create_media(%{
|
||||
file: Map.take(uploaded, [:url, :name, :content_type, :size]),
|
||||
metadata: Map.take(uploaded, [:width, :height, :blurhash]),
|
||||
actor_id: actor_id
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user