Add Credo checks and refactor code
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Make Logger.debug calls lazy Signed-off-by: Thomas Citharel <tcit@tcit.fr> Add missing @moduledocs Signed-off-by: Thomas Citharel <tcit@tcit.fr> Refactor according to credo Signed-off-by: Thomas Citharel <tcit@tcit.fr> Final fixes and add credo to CI Signed-off-by: Thomas Citharel <tcit@tcit.fr> Closes #52
This commit is contained in:
@@ -43,14 +43,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
def insert(map, local \\ true) when is_map(map) do
|
||||
with map <- lazy_put_activity_defaults(map),
|
||||
:ok <- insert_full_object(map) do
|
||||
object_id =
|
||||
cond do
|
||||
is_map(map["object"]) ->
|
||||
map["object"]["id"]
|
||||
|
||||
is_binary(map["object"]) ->
|
||||
map["id"]
|
||||
end
|
||||
object_id = if is_map(map["object"]), do: map["object"]["id"], else: map["id"]
|
||||
|
||||
map = if local, do: Map.put(map, "id", "#{object_id}/activity"), else: map
|
||||
|
||||
@@ -384,7 +377,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
json = Jason.encode!(data)
|
||||
Logger.debug("Remote inboxes are : #{inspect(remote_inboxes)}")
|
||||
Logger.debug(fn -> "Remote inboxes are : #{inspect(remote_inboxes)}" end)
|
||||
|
||||
Enum.each(remote_inboxes, fn inbox ->
|
||||
Federator.enqueue(:publish_single_ap, %{
|
||||
|
||||
@@ -48,28 +48,35 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
|> fix_tag
|
||||
end
|
||||
|
||||
def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object)
|
||||
when not is_nil(in_reply_to) and is_bitstring(in_reply_to) do
|
||||
in_reply_to |> do_fix_in_reply_to(object)
|
||||
end
|
||||
|
||||
def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object)
|
||||
when not is_nil(in_reply_to) and is_map(in_reply_to) do
|
||||
if is_bitstring(in_reply_to["id"]) do
|
||||
in_reply_to["id"] |> do_fix_in_reply_to(object)
|
||||
end
|
||||
end
|
||||
|
||||
def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object)
|
||||
when not is_nil(in_reply_to) and is_list(in_reply_to) do
|
||||
if is_bitstring(Enum.at(in_reply_to, 0)) do
|
||||
in_reply_to |> Enum.at(0) |> do_fix_in_reply_to(object)
|
||||
end
|
||||
end
|
||||
|
||||
def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object)
|
||||
when not is_nil(in_reply_to) do
|
||||
in_reply_to_id =
|
||||
cond do
|
||||
# If the inReplyTo is just an AP ID
|
||||
is_bitstring(in_reply_to) ->
|
||||
in_reply_to
|
||||
Logger.error("inReplyTo ID seem incorrect")
|
||||
Logger.error(inspect(in_reply_to))
|
||||
do_fix_in_reply_to("", object)
|
||||
end
|
||||
|
||||
# If the inReplyTo is a object itself
|
||||
is_map(in_reply_to) && is_bitstring(in_reply_to["id"]) ->
|
||||
in_reply_to["id"]
|
||||
|
||||
# If the inReplyTo is an array
|
||||
is_list(in_reply_to) && is_bitstring(Enum.at(in_reply_to, 0)) ->
|
||||
Enum.at(in_reply_to, 0)
|
||||
|
||||
true ->
|
||||
Logger.error("inReplyTo ID seem incorrect")
|
||||
Logger.error(inspect(in_reply_to))
|
||||
""
|
||||
end
|
||||
def fix_in_reply_to(object), do: object
|
||||
|
||||
def do_fix_in_reply_to(in_reply_to_id, object) do
|
||||
case fetch_obj_helper(in_reply_to_id) do
|
||||
{:ok, replied_object} ->
|
||||
object
|
||||
@@ -85,8 +92,6 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
end
|
||||
end
|
||||
|
||||
def fix_in_reply_to(object), do: object
|
||||
|
||||
def fix_attachments(object) do
|
||||
attachments =
|
||||
(object["attachment"] || [])
|
||||
@@ -500,7 +505,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
|
||||
@spec normalize(String.t()) :: struct() | nil
|
||||
def get_anything_by_url(url) do
|
||||
Logger.debug("Getting anything from url #{url}")
|
||||
Logger.debug(fn -> "Getting anything from url #{url}" end)
|
||||
get_actor_url(url) || get_event_url(url) || get_comment_url(url)
|
||||
end
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
data =
|
||||
if Map.has_key?(object_data, "inReplyTo") && object_data["inReplyTo"] != nil &&
|
||||
object_data["inReplyTo"] != "" do
|
||||
Logger.debug("Object has inReplyTo #{object_data["inReplyTo"]}")
|
||||
Logger.debug(fn -> "Object has inReplyTo #{object_data["inReplyTo"]}" end)
|
||||
|
||||
case ActivityPub.fetch_object_from_url(object_data["inReplyTo"]) do
|
||||
# Reply to an event (Comment)
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/formatter.ex
|
||||
|
||||
defmodule Mobilizon.Service.Formatter do
|
||||
@moduledoc """
|
||||
Formats input text to structured data, extracts mentions and hashtags
|
||||
"""
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Actors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user