twitter api: user view: expose user notification settings under pleroma object
authorWilliam Pitcock <nenolod@dereferenced.org>
Sat, 25 May 2019 05:31:13 +0000 (05:31 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sat, 25 May 2019 05:31:13 +0000 (05:31 +0000)
lib/pleroma/web/twitter_api/views/user_view.ex
test/web/twitter_api/views/user_view_test.exs

index f0a4ddbd3be1964eeb2116682bb20e87da4387d5..550f35f5f796f688213279b3e4400c018813bc49 100644 (file)
@@ -121,6 +121,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
             "tags" => user.tags
           }
           |> maybe_with_activation_status(user, for_user)
+          |> with_notification_settings(user, for_user)
       }
       |> maybe_with_user_settings(user, for_user)
       |> maybe_with_role(user, for_user)
@@ -132,6 +133,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
     end
   end
 
+  defp with_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
+    Map.put(data, "notification_settings", user.info.notification_settings)
+  end
+
+  defp with_notification_settings(data, _, _), do: data
+
   defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
     Map.put(data, "deactivated", user.info.deactivated)
   end
index 74526673c2959034b72b84618bbc194be36fd1ad..a48fc9b784ddeb6207e411210178504ad926c510 100644 (file)
@@ -112,9 +112,11 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
     as_user = UserView.render("show.json", %{user: user, for: user})
     assert as_user["default_scope"] == user.info.default_scope
     assert as_user["no_rich_text"] == user.info.no_rich_text
+    assert as_user["pleroma"]["notification_settings"] == user.info.notification_settings
     as_stranger = UserView.render("show.json", %{user: user})
     refute as_stranger["default_scope"]
     refute as_stranger["no_rich_text"]
+    refute as_stranger["pleroma"]["notification_settings"]
   end
 
   test "A user for a given other follower", %{user: user} do