CommonAPI: Replies to conversations also get the correct context id.
authorlain <lain@soykaf.club>
Mon, 5 Aug 2019 13:33:22 +0000 (15:33 +0200)
committerlain <lain@soykaf.club>
Mon, 5 Aug 2019 13:33:22 +0000 (15:33 +0200)
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/common_api/utils.ex
test/web/common_api/common_api_test.exs

index 86e95cd0f641cba42fabfe652620d68c92a8545a..72da46263f6f16f8f453d3b4cc0ddbcb8d7e6329 100644 (file)
@@ -223,7 +223,7 @@ defmodule Pleroma.Web.CommonAPI do
          {poll, poll_emoji} <- make_poll_data(data),
          {to, cc} <-
            get_to_and_cc(user, addressed_users, in_reply_to, visibility, in_reply_to_conversation),
-         context <- make_context(in_reply_to),
+         context <- make_context(in_reply_to, in_reply_to_conversation),
          cw <- data["spoiler_text"] || "",
          sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
          full_payload <- String.trim(status <> cw),
index e70ba7d43c2ee25f8fc1b98e6c2a0ca27459bd12..425b6d656a10a455d3500d854845456c69db0a27 100644 (file)
@@ -244,8 +244,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do
 
   defp maybe_add_nsfw_tag(data, _), do: data
 
-  def make_context(%Activity{data: %{"context" => context}}), do: context
-  def make_context(_), do: Utils.generate_context_id()
+  def make_context(_, %Participation{} = participation) do
+    Repo.preload(participation, :conversation).conversation.ap_id
+  end
+
+  def make_context(%Activity{data: %{"context" => context}}, _), do: context
+  def make_context(_, _), do: Utils.generate_context_id()
 
   def maybe_add_attachments(parsed, _attachments, true = _no_links), do: parsed
 
index e2a5bf117f6a919fcdfbce45dde15821d6f86e14..4545233496622d866a844194bdfb9a9dc362ade9 100644 (file)
@@ -9,10 +9,25 @@ defmodule Pleroma.Web.CommonAPITest do
   alias Pleroma.Object
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
+  alias Pleroma.Web.ActivityPub.Visibility
   alias Pleroma.Web.CommonAPI
 
   import Pleroma.Factory
 
+  test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
+    user = insert(:user)
+    {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+
+    [participation] = Participation.for_user(user)
+
+    {:ok, convo_reply} =
+      CommonAPI.post(user, %{"status" => ".", "in_reply_to_conversation_id" => participation.id})
+
+    assert Visibility.is_direct?(convo_reply)
+
+    assert activity.data["context"] == convo_reply.data["context"]
+  end
+
   test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
     har = insert(:user)
     jafnhar = insert(:user)