From 7945430477b9e1feac3c87f7fa1dd9f4d5eb10df Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 8 Nov 2018 17:40:26 +0100 Subject: [PATCH] Refactor and add logging to insert comment fct Signed-off-by: Thomas Citharel --- lib/service/activity_pub/utils.ex | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/service/activity_pub/utils.ex b/lib/service/activity_pub/utils.ex index 294de387e..b5859a022 100644 --- a/lib/service/activity_pub/utils.ex +++ b/lib/service/activity_pub/utils.ex @@ -146,25 +146,34 @@ 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 = + 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 - end + else + Logger.debug("No parent object for this comment") + data + end require Logger Logger.info("comment data ready to be inserted")