From 4f6de34f4f40d408fb9200a5c4c908aec3ed9e91 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 23 Jun 2018 06:53:29 +0000 Subject: [PATCH 1/4] mastodon api: use info["default_scope"] if available for post scope --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 9d3f526c9..09e6b0b59 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -873,7 +873,7 @@ def index(%{assigns: %{user: user}} = conn, _params) do }, compose: %{ me: "#{user.id}", - default_privacy: "public", + default_privacy: user.info["default_scope"] || "public", default_sensitive: false }, media_attachments: %{ From dcdf7b6686fe3732ac8f9a93570dfa8a1412783a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 23 Jun 2018 06:55:32 +0000 Subject: [PATCH 2/4] twitter api: user view: show default message scope if known --- lib/pleroma/web/twitter_api/views/user_view.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 711008973..9c8460378 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -52,7 +52,8 @@ def render("user.json", %{user: user = %User{}} = assigns) do "cover_photo" => User.banner_url(user) |> MediaProxy.url(), "background_image" => image_url(user.info["background"]) |> MediaProxy.url(), "is_local" => user.local, - "locked" => !!user.info["locked"] + "locked" => !!user.info["locked"], + "default_scope" => user.info["default_scope"] || "public" } if assigns[:token] do From 2f14996d9afedbc4dbd75a518cf191636f926f74 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 23 Jun 2018 07:02:49 +0000 Subject: [PATCH 3/4] twitter api: allow setting default_scope --- .../web/twitter_api/twitter_api_controller.ex | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 8f5b3c786..65e67396b 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -431,6 +431,19 @@ def update_profile(%{assigns: %{user: user}} = conn, params) do user end + user = + if default_scope = params["default_scope"] do + with new_info <- Map.put(user.info, "default_scope", default_scope), + change <- User.info_changeset(user, %{info: new_info}), + {:ok, user} <- User.update_and_set_cache(change) do + user + else + _e -> user + end + else + user + end + with changeset <- User.update_changeset(user, params), {:ok, user} <- User.update_and_set_cache(changeset) do CommonAPI.update(user) From 32211c4ada3ea113fb4041ae28b884130b2f4342 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 24 Jun 2018 06:31:09 +0000 Subject: [PATCH 4/4] tests: add default_scope where appropriate --- test/web/twitter_api/views/user_view_test.exs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index eea743b32..49f73c2fe 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -60,7 +60,8 @@ test "A user" do "cover_photo" => banner, "background_image" => nil, "is_local" => true, - "locked" => false + "locked" => false, + "default_scope" => "public" } assert represented == UserView.render("show.json", %{user: user}) @@ -96,7 +97,8 @@ test "A user for a given other follower", %{user: user} do "cover_photo" => banner, "background_image" => nil, "is_local" => true, - "locked" => false + "locked" => false, + "default_scope" => "public" } assert represented == UserView.render("show.json", %{user: user, for: follower}) @@ -133,7 +135,8 @@ test "A user that follows you", %{user: user} do "cover_photo" => banner, "background_image" => nil, "is_local" => true, - "locked" => false + "locked" => false, + "default_scope" => "public" } assert represented == UserView.render("show.json", %{user: follower, for: user}) @@ -177,7 +180,8 @@ test "A blocked user for the blocker" do "cover_photo" => banner, "background_image" => nil, "is_local" => true, - "locked" => false + "locked" => false, + "default_scope" => "public" } blocker = Repo.get(User, blocker.id)