Allow users to announce privately, including own private notes
authorThibaut Girka <thib@sitedethib.com>
Tue, 1 Oct 2019 16:38:23 +0000 (18:38 +0200)
committerThibaut Girka <thib@sitedethib.com>
Tue, 1 Oct 2019 18:00:59 +0000 (20:00 +0200)
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/mastodon_api/controllers/status_controller.ex

index 2ec017ff87e1316f38ac70208babce335330059a..677a53ddfb8a37471d7d8245c25f8e8619b51cbf 100644 (file)
@@ -76,11 +76,12 @@ defmodule Pleroma.Web.CommonAPI do
     end
   end
 
-  def repeat(id_or_ap_id, user) do
+  def repeat(id_or_ap_id, user, params \\ %{}) do
     with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
          object <- Object.normalize(activity),
-         nil <- Utils.get_existing_announce(user.ap_id, object) do
-      ActivityPub.announce(user, object)
+         nil <- Utils.get_existing_announce(user.ap_id, object),
+         public <- get_announce_visibility(object, params) do
+      ActivityPub.announce(user, object, nil, true, public)
     else
       _ -> {:error, dgettext("errors", "Could not repeat")}
     end
@@ -169,6 +170,14 @@ defmodule Pleroma.Web.CommonAPI do
     end
   end
 
+  def get_announce_visibility(_, %{"visibility" => visibility})
+      when visibility in ~w{public unlisted private direct},
+      do: visibility in ~w(public unlisted)
+
+  def get_announce_visibility(object, _) do
+    Visibility.is_public?(object)
+  end
+
   def get_visibility(_, _, %Participation{}), do: {"direct", "direct"}
 
   def get_visibility(%{"visibility" => visibility}, in_reply_to, _)
index fb6fd76768c379294081bc85fa7de9d3e40ab449..51456d453f2f6e070c99347198503cf557ca2bd2 100644 (file)
@@ -125,8 +125,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
   end
 
   @doc "POST /api/v1/statuses/:id/reblog"
-  def reblog(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
-    with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user),
+  def reblog(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id} = params) do
+    with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user, params),
          %Activity{} = announce <- Activity.normalize(announce.data) do
       try_render(conn, "show.json", %{activity: announce, for: user, as: :activity})
     end