update api to set skip_thread_containment
authorMaksim Pechnikov <parallel588@gmail.com>
Mon, 3 Jun 2019 18:02:02 +0000 (21:02 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Mon, 3 Jun 2019 18:02:57 +0000 (21:02 +0300)
docs/api/differences_in_mastoapi_responses.md
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
lib/pleroma/web/twitter_api/views/user_view.ex
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/twitter_api/twitter_api_controller_test.exs

index 36b47608e1655913e3cf8d127b11a4067b7113f1..ed156836d6ccc328a73fa205690dd2d3717bb94f 100644 (file)
@@ -80,6 +80,7 @@ Additional parameters can be added to the JSON body/Form data:
 - `hide_favorites` - if true, user's favorites timeline will be hidden
 - `show_role` - if true, user's role (e.g admin, moderator) will be exposed to anyone in the API
 - `default_scope` - the scope returned under `privacy` key in Source subentity
+- `skip_thread_containment` - if true, skip filtering out broken threads
 
 ## Authentication
 
index 0d81fb840fa7dbf83749f9fbfa528d6d246e99d3..52eed51c164689d4fe6ecca1a8abeee4c93fdd18 100644 (file)
@@ -117,7 +117,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
       |> Enum.dedup()
 
     info_params =
-      [:no_rich_text, :locked, :hide_followers, :hide_follows, :hide_favorites, :show_role]
+      [
+        :no_rich_text,
+        :locked,
+        :hide_followers,
+        :hide_follows,
+        :hide_favorites,
+        :show_role,
+        :skip_thread_containment
+      ]
       |> Enum.reduce(%{}, fn key, acc ->
         add_if_present(acc, params, to_string(key), key, fn value ->
           {:ok, ControllerHelper.truthy_param?(value)}
index b82d3319b4c4d40da6ef356ed61eb2b0e00dca91..7b7e58eac782eabf2ccdd732699e7e1e7ab242f4 100644 (file)
@@ -124,7 +124,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
         hide_followers: user.info.hide_followers,
         hide_follows: user.info.hide_follows,
         hide_favorites: user.info.hide_favorites,
-        relationship: relationship
+        relationship: relationship,
+        skip_thread_containment: user.info.skip_thread_containment
       }
     }
     |> maybe_put_role(user, opts[:for])
index 1b6b33e6973eebcc1b507cfee631e340156c9c37..6cf107d172c48164f14600d9df0f5ed14bf64a84 100644 (file)
@@ -632,7 +632,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
 
   defp build_info_cng(user, params) do
     info_params =
-      ["no_rich_text", "locked", "hide_followers", "hide_follows", "hide_favorites", "show_role"]
+      [
+        "no_rich_text",
+        "locked",
+        "hide_followers",
+        "hide_follows",
+        "hide_favorites",
+        "show_role",
+        "skip_thread_containment"
+      ]
       |> Enum.reduce(%{}, fn key, res ->
         if value = params[key] do
           Map.put(res, key, value == "true")
index f0a4ddbd3be1964eeb2116682bb20e87da4387d5..84875613a50f8aa168017eaed64d65c465a7bbc7 100644 (file)
@@ -118,7 +118,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
         "pleroma" =>
           %{
             "confirmation_pending" => user_info.confirmation_pending,
-            "tags" => user.tags
+            "tags" => user.tags,
+            "skip_thread_containment" => user.info.skip_thread_containment
           }
           |> maybe_with_activation_status(user, for_user)
       }
index f5f87d8afe85715e7e09cdc52a3a06eb983317a7..587df04815f455718738237cf48269459d48f243 100644 (file)
@@ -2378,6 +2378,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       assert user["pleroma"]["hide_followers"] == true
     end
 
+    test "updates the user's skip_thread_containment option", %{conn: conn} do
+      user = insert(:user)
+
+      response =
+        conn
+        |> assign(:user, user)
+        |> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
+        |> json_response(200)
+
+      assert response["pleroma"]["skip_thread_containment"] == true
+      assert refresh_record(user).info.skip_thread_containment
+    end
+
     test "updates the user's hide_follows status", %{conn: conn} do
       user = insert(:user)
 
index bcd0f522d5c9b8edf2e3d13fad9300416bf37aa5..8187ffd0ee1dadde12f542aeeafdee4e50bddf02 100644 (file)
@@ -1495,7 +1495,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
           "hide_follows" => "false"
         })
 
-      user = Repo.get!(User, user.id)
+      user = refresh_record(user)
       assert user.info.hide_follows == false
       assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
     end
@@ -1548,6 +1548,29 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
       assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
     end
 
+    test "it sets and un-sets skip_thread_containment", %{conn: conn} do
+      user = insert(:user)
+
+      response =
+        conn
+        |> assign(:user, user)
+        |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "true"})
+        |> json_response(200)
+
+      assert response["pleroma"]["skip_thread_containment"] == true
+      user = refresh_record(user)
+      assert user.info.skip_thread_containment
+
+      response =
+        conn
+        |> assign(:user, user)
+        |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "false"})
+        |> json_response(200)
+
+      assert response["pleroma"]["skip_thread_containment"] == false
+      refute refresh_record(user).info.skip_thread_containment
+    end
+
     test "it locks an account", %{conn: conn} do
       user = insert(:user)