Add "listMessage"
authorEgor Kislitsyn <egor@kislitsyn.com>
Thu, 11 Jul 2019 09:36:08 +0000 (16:36 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Thu, 11 Jul 2019 09:36:08 +0000 (16:36 +0700)
lib/pleroma/web/activity_pub/publisher.ex
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/common_api/utils.ex
test/web/common_api/common_api_test.exs

index b7dc90caa554e4a68896c66170a01fedfe3a0cc5..ffdd33351510ed2d18d1c9e9b68bef6d4e9c93d4 100644 (file)
@@ -136,7 +136,6 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
       json =
         data
         |> Map.put("cc", cc)
-        |> Map.put("directMessage", true)
         |> Jason.encode!()
 
       Pleroma.Web.Federator.Publisher.enqueue_one(__MODULE__, %{
index 8e3892bdf778d3743c9219d34551b7b817d00f51..1c47a31d76be0c919403a6a24c99e59036e3c3e7 100644 (file)
@@ -215,7 +215,6 @@ defmodule Pleroma.Web.CommonAPI do
          addressed_users <- get_addressed_users(mentioned_users, data["to"]),
          {poll, poll_emoji} <- make_poll_data(data),
          {to, cc} <- get_to_and_cc(user, addressed_users, in_reply_to, visibility),
-         bcc <- bcc_for_list(user, visibility),
          context <- make_context(in_reply_to),
          cw <- data["spoiler_text"] || "",
          sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
@@ -241,16 +240,21 @@ defmodule Pleroma.Web.CommonAPI do
              "emoji",
              Map.merge(Formatter.get_emoji_map(full_payload), poll_emoji)
            ) do
-      ActivityPub.create(
-        %{
-          to: to,
-          actor: user,
-          context: context,
-          object: object,
-          additional: %{"cc" => cc, "bcc" => bcc, "directMessage" => visibility == "direct"}
-        },
-        Pleroma.Web.ControllerHelper.truthy_param?(data["preview"]) || false
-      )
+      preview? = Pleroma.Web.ControllerHelper.truthy_param?(data["preview"]) || false
+      direct? = visibility == "direct"
+
+      additional_data =
+        %{"cc" => cc, "directMessage" => direct?} |> maybe_add_list_data(user, visibility)
+
+      params = %{
+        to: to,
+        actor: user,
+        context: context,
+        object: object,
+        additional: additional_data
+      }
+
+      ActivityPub.create(params, preview?)
     else
       {:private_to_public, true} ->
         {:error, dgettext("errors", "The message visibility must be direct")}
index d4bfdd7e40fd55cec353391f2295d01ed7ceab86..94b2c50fc294a0b0ccb060db21a99a2c4fef6f78 100644 (file)
@@ -108,12 +108,19 @@ defmodule Pleroma.Web.CommonAPI.Utils do
 
   def get_addressed_users(mentioned_users, _), do: mentioned_users
 
-  def bcc_for_list(user, {:list, list_id}) do
-    list = Pleroma.List.get(list_id, user)
-    [list.ap_id]
+  def maybe_add_list_data(additional_data, user, {:list, list_id}) do
+    case Pleroma.List.get(list_id, user) do
+      %Pleroma.List{} = list ->
+        additional_data
+        |> Map.put("listMessage", list.ap_id)
+        |> Map.put("bcc", [list.ap_id])
+
+      _ ->
+        additional_data
+    end
   end
 
-  def bcc_for_list(_, _), do: []
+  def maybe_add_list_data(additional_data, _, _), do: additional_data
 
   def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data)
       when is_list(options) do
index 694b52356d621b45f1161d2e30c9a0a9ccd80732..932c6877df734891f14818d1b4f0c8171d578f08 100644 (file)
@@ -139,6 +139,7 @@ defmodule Pleroma.Web.CommonAPITest do
 
       assert activity.data["bcc"] == [list.ap_id]
       assert activity.recipients == [list.ap_id, user.ap_id]
+      assert activity.data["listMessage"] == list.ap_id
     end
   end