Support `list` visibility in StatusView
authorEgor Kislitsyn <egor@kislitsyn.com>
Mon, 15 Jul 2019 07:00:29 +0000 (14:00 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 15 Jul 2019 07:00:29 +0000 (14:00 +0700)
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/common_api/utils.ex
test/web/mastodon_api/status_view_test.exs

index 1c47a31d76be0c919403a6a24c99e59036e3c3e7..f764e87af7a4e02afafca43346764c3dfcf660d8 100644 (file)
@@ -243,18 +243,15 @@ defmodule Pleroma.Web.CommonAPI do
       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
+        additional: %{"cc" => cc, "directMessage" => direct?}
       }
-
-      ActivityPub.create(params, preview?)
+      |> maybe_add_list_data(user, visibility)
+      |> ActivityPub.create(preview?)
     else
       {:private_to_public, true} ->
         {:error, dgettext("errors", "The message visibility must be direct")}
index 94b2c50fc294a0b0ccb060db21a99a2c4fef6f78..fed5f9de7925f41b355177406644916eeb3be6f8 100644 (file)
@@ -108,19 +108,20 @@ defmodule Pleroma.Web.CommonAPI.Utils do
 
   def get_addressed_users(mentioned_users, _), do: mentioned_users
 
-  def maybe_add_list_data(additional_data, user, {:list, list_id}) do
+  def maybe_add_list_data(activity_params, 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])
+        activity_params
+        |> put_in([:additional, "bcc"], [list.ap_id])
+        |> put_in([:additional, "listMessage"], list.ap_id)
+        |> put_in([:object, "listMessage"], list.ap_id)
 
       _ ->
-        additional_data
+        activity_params
     end
   end
 
-  def maybe_add_list_data(additional_data, _, _), do: additional_data
+  def maybe_add_list_data(activity_params, _, _), do: activity_params
 
   def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data)
       when is_list(options) do
index ac42819d8e4a20ac278f8aff10d88b1f1b554885..995bd52c83961e507df882681d08cb4c2155372c 100644 (file)
@@ -541,4 +541,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     assert result[:reblog][:account][:pleroma][:relationship] ==
              AccountView.render("relationship.json", %{user: user, target: user})
   end
+
+  test "visibility/list" do
+    user = insert(:user)
+
+    {:ok, list} = Pleroma.List.create("foo", user)
+
+    {:ok, activity} =
+      CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+    status = StatusView.render("status.json", activity: activity)
+
+    assert status.visibility == "list"
+  end
 end