Merge remote-tracking branch 'pleroma/develop' into feature/addressable-lists
authorEgor Kislitsyn <egor@kislitsyn.com>
Thu, 16 May 2019 10:54:24 +0000 (17:54 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Thu, 16 May 2019 10:54:24 +0000 (17:54 +0700)
1  2 
CHANGELOG.md
lib/pleroma/web/activity_pub/publisher.ex
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

diff --cc CHANGELOG.md
Simple merge
index ed2c0017f0fb86638dc4f83f8331b9233c4e07bb,29c4c101425b6f4190d3b2188dc28ef0b29dc194..97134cd1937064979c818074115fd24a9362f229
@@@ -116,24 -116,22 +116,27 @@@ defmodule Pleroma.Web.CommonAPI d
      end
    end
  
-   def get_visibility(%{"visibility" => visibility})
+   def get_visibility(%{"visibility" => visibility}, in_reply_to)
        when visibility in ~w{public unlisted private direct},
-       do: visibility
+       do: {visibility, get_replied_to_visibility(in_reply_to)}
  
-   def get_visibility(%{"visibility" => "list:" <> list_id}) do
-     {:list, String.to_integer(list_id)}
++  def get_visibility(%{"visibility" => "list:" <> list_id}, in_reply_to) do
++    visibility = {:list, String.to_integer(list_id)}
++    {visibility, get_replied_to_visibility(in_reply_to)}
 +  end
 +
-   def get_visibility(%{"in_reply_to_status_id" => status_id}) when not is_nil(status_id) do
-     case get_replied_to_activity(status_id) do
-       nil ->
-         "public"
+   def get_visibility(_, in_reply_to) when not is_nil(in_reply_to) do
+     visibility = get_replied_to_visibility(in_reply_to)
+     {visibility, visibility}
+   end
+   def get_visibility(_, in_reply_to), do: {"public", get_replied_to_visibility(in_reply_to)}
+   def get_replied_to_visibility(nil), do: nil
  
-       in_reply_to ->
-         # XXX: these heuristics should be moved out of MastodonAPI.
-         with %Object{} = object <- Object.normalize(in_reply_to) do
-           Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
-         end
+   def get_replied_to_visibility(activity) do
+     with %Object{} = object <- Object.normalize(activity) do
+       Pleroma.Web.ActivityPub.Visibility.get_visibility(object)
      end
    end
  
               "emoji",
               Formatter.get_emoji_map(full_payload)
             ) do
 -      res =
 -        ActivityPub.create(
 -          %{
 -            to: to,
 -            actor: user,
 -            context: context,
 -            object: object,
 -            additional: %{"cc" => cc, "directMessage" => visibility == "direct"}
 -          },
 -          Pleroma.Web.ControllerHelper.truthy_param?(data["preview"]) || false
 -        )
 -
 -      res
 +      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
 +      )
+     else
+       e -> {:error, e}
      end
    end
  
index 11f3c8357caf9405affe3e89f8ebfc39e29d4556,8d4f401eec8a0303cac3c8d17243af9590589ade..23e89d685184eb871d9254b263e3a66173fa68b6
@@@ -88,18 -88,27 +88,40 @@@ defmodule Pleroma.Web.CommonAPITest d
        assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
      end
  
+     test "it does not allow replies to direct messages that are not direct messages themselves" do
+       user = insert(:user)
+       {:ok, activity} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
+       assert {:ok, _} =
+                CommonAPI.post(user, %{
+                  "status" => "suya..",
+                  "visibility" => "direct",
+                  "in_reply_to_status_id" => activity.id
+                })
+       Enum.each(["public", "private", "unlisted"], fn visibility ->
+         assert {:error, {:private_to_public, _}} =
+                  CommonAPI.post(user, %{
+                    "status" => "suya..",
+                    "visibility" => visibility,
+                    "in_reply_to_status_id" => activity.id
+                  })
+       end)
+     end
++
 +    test "it allows to address a list" do
 +      user = insert(:user)
 +      {:ok, list} = Pleroma.List.create("foo", user)
 +
 +      list_ap_id = Pleroma.List.ap_id(user, list.id)
 +
 +      {:ok, activity} =
 +        CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
 +
 +      assert activity.data["bcc"] == [list_ap_id]
 +      assert activity.recipients == [list_ap_id, user.ap_id]
 +    end
    end
  
    describe "reactions" do