From c0ca9f82b991d89524a8f0f770f4b7b08da59e2f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 May 2018 04:15:42 +0000 Subject: [PATCH] mastodon api: properly track if an account is locked or not --- lib/pleroma/user.ex | 3 ++- lib/pleroma/web/activity_pub/activity_pub.ex | 4 +++- lib/pleroma/web/activity_pub/views/user_view.ex | 2 +- lib/pleroma/web/mastodon_api/views/account_view.ex | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 690cc7cf3..2e57f2b43 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -67,7 +67,8 @@ def user_info(%User{} = user) do %{ following_count: length(user.following) - oneself, note_count: user.info["note_count"] || 0, - follower_count: user.info["follower_count"] || 0 + follower_count: user.info["follower_count"] || 0, + locked: user.info["locked"] || false } end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 8485a8009..30211072b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -464,6 +464,7 @@ def user_data_from_user_object(data) do "url" => [%{"href" => data["image"]["url"]}] } + locked = data["manuallyApprovesFollowers"] || false data = Transmogrifier.maybe_fix_user_object(data) user_data = %{ @@ -471,7 +472,8 @@ def user_data_from_user_object(data) do info: %{ "ap_enabled" => true, "source_data" => data, - "banner" => banner + "banner" => banner, + "locked" => locked }, avatar: avatar, nickname: "#{data["preferredUsername"]}@#{URI.parse(data["id"]).host}", diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index ffd76b529..f4b2e0610 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -26,7 +26,7 @@ def render("user.json", %{user: user}) do "name" => user.name, "summary" => user.bio, "url" => user.ap_id, - "manuallyApprovesFollowers" => false, + "manuallyApprovesFollowers" => user.info["locked"] || false, "publicKey" => %{ "id" => "#{user.ap_id}#main-key", "owner" => user.ap_id, diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index f378bb36e..9db683f44 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -19,7 +19,7 @@ def render("account.json", %{user: user}) do username: hd(String.split(user.nickname, "@")), acct: user.nickname, display_name: user.name || user.nickname, - locked: false, + locked: user_info.locked, created_at: Utils.to_masto_date(user.inserted_at), followers_count: user_info.follower_count, following_count: user_info.following_count,