Refactor and add logging to insert comment fct
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
acf110a761
commit
26548cdfaa
@ -146,24 +146,33 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
}
|
||||
|
||||
# We fetch the parent object
|
||||
unless !Map.has_key?(object_data, "inReplyTo") || object_data["inReplyTo"] == nil ||
|
||||
object_data["inReplyTo"] == "" 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"]}")
|
||||
|
||||
case ActivityPub.fetch_object_from_url(object_data["inReplyTo"]) do
|
||||
# Reply to an event (Comment)
|
||||
{:ok, %Event{id: id}} ->
|
||||
Logger.debug("Parent object is an event")
|
||||
data |> Map.put("event_id", id)
|
||||
|
||||
# Reply to a comment (Comment)
|
||||
{:ok, %Comment{id: id} = comment} ->
|
||||
Logger.debug("Parent object is another comment")
|
||||
|
||||
data
|
||||
|> Map.put("in_reply_to_comment_id", id)
|
||||
|> Map.put("origin_comment_id", comment |> Comment.get_thread_id())
|
||||
|
||||
# Anthing else is kind of a MP
|
||||
_ ->
|
||||
Logger.debug("Parent object is something we don't handle")
|
||||
data
|
||||
end
|
||||
else
|
||||
Logger.debug("No parent object for this comment")
|
||||
data
|
||||
end
|
||||
|
||||
require Logger
|
||||
|
Loading…
Reference in New Issue
Block a user