Refactor and add logging to insert comment fct

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-11-08 17:40:26 +01:00
parent acf110a761
commit 26548cdfaa

View File

@ -146,25 +146,34 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
} }
# We fetch the parent object # We fetch the parent object
unless !Map.has_key?(object_data, "inReplyTo") || object_data["inReplyTo"] == nil || data =
object_data["inReplyTo"] == "" do if Map.has_key?(object_data, "inReplyTo") && object_data["inReplyTo"] != nil &&
data = object_data["inReplyTo"] != "" do
Logger.debug("Object has inReplyTo #{object_data["inReplyTo"]}")
case ActivityPub.fetch_object_from_url(object_data["inReplyTo"]) do case ActivityPub.fetch_object_from_url(object_data["inReplyTo"]) do
# Reply to an event (Comment) # Reply to an event (Comment)
{:ok, %Event{id: id}} -> {:ok, %Event{id: id}} ->
Logger.debug("Parent object is an event")
data |> Map.put("event_id", id) data |> Map.put("event_id", id)
# Reply to a comment (Comment) # Reply to a comment (Comment)
{:ok, %Comment{id: id} = comment} -> {:ok, %Comment{id: id} = comment} ->
Logger.debug("Parent object is another comment")
data data
|> Map.put("in_reply_to_comment_id", id) |> Map.put("in_reply_to_comment_id", id)
|> Map.put("origin_comment_id", comment |> Comment.get_thread_id()) |> Map.put("origin_comment_id", comment |> Comment.get_thread_id())
# Anthing else is kind of a MP # Anthing else is kind of a MP
_ -> _ ->
Logger.debug("Parent object is something we don't handle")
data data
end end
end else
Logger.debug("No parent object for this comment")
data
end
require Logger require Logger
Logger.info("comment data ready to be inserted") Logger.info("comment data ready to be inserted")