Address grouped notification review cleanup
This commit is contained in:
parent
a2a23b327b
commit
fc9e6793ce
2 changed files with 43 additions and 39 deletions
|
|
@ -73,7 +73,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
def get_grouped_notification_page(user, params \\ %{}) do
|
||||
grouped_types =
|
||||
params
|
||||
|> Map.get("grouped_types", Map.get(params, :grouped_types))
|
||||
|> Map.get("grouped_types")
|
||||
|> Notification.normalize_grouped_types()
|
||||
|
||||
query = notifications_query(user, params)
|
||||
|
|
@ -98,13 +98,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
}
|
||||
end
|
||||
|
||||
def get_grouped_notification_groups(user, params \\ %{}) do
|
||||
{groups, _notifications, _notification_group_counts, _notification_group_bounds} =
|
||||
get_grouped_notification_page(user, params)
|
||||
|
||||
groups
|
||||
end
|
||||
|
||||
def get_notification_group_result(user, group_key, params \\ %{}) do
|
||||
notifications = notification_group_sample(user, params, group_key)
|
||||
metadata = notification_group_metadata(user, group_key, params)
|
||||
|
|
@ -163,21 +156,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
|
||||
defp group_pagination(params) do
|
||||
cond do
|
||||
min_id = Map.get(params, "min_id", Map.get(params, :min_id)) ->
|
||||
min_id = Map.get(params, "min_id") ->
|
||||
cursor_filters = [{:gt, min_id}]
|
||||
|
||||
cursor_filters =
|
||||
case Map.get(params, "max_id", Map.get(params, :max_id)) do
|
||||
case Map.get(params, "max_id") do
|
||||
nil -> cursor_filters
|
||||
max_id -> [{:lt, max_id} | cursor_filters]
|
||||
end
|
||||
|
||||
{:asc, cursor_filters}
|
||||
|
||||
since_id = Map.get(params, "since_id", Map.get(params, :since_id)) ->
|
||||
since_id = Map.get(params, "since_id") ->
|
||||
{:desc, [{:gt, since_id}]}
|
||||
|
||||
max_id = Map.get(params, "max_id", Map.get(params, :max_id)) ->
|
||||
max_id = Map.get(params, "max_id") ->
|
||||
{:desc, [{:lt, max_id}]}
|
||||
|
||||
true ->
|
||||
|
|
@ -187,7 +180,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
|
||||
defp grouped_limit(params) do
|
||||
params
|
||||
|> Map.get("limit", Map.get(params, :limit, 40))
|
||||
|> Map.get("limit", 40)
|
||||
|> parse_limit(40)
|
||||
|> min(80)
|
||||
end
|
||||
|
|
@ -195,7 +188,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
def unread_notification_group_count(user, params \\ %{}) do
|
||||
grouped_types =
|
||||
params
|
||||
|> Map.get("grouped_types", Map.get(params, :grouped_types))
|
||||
|> Map.get("grouped_types")
|
||||
|> Notification.normalize_grouped_types()
|
||||
|
||||
limit = unread_count_limit(params)
|
||||
|
|
@ -406,7 +399,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
|
||||
defp unread_count_limit(params) do
|
||||
params
|
||||
|> Map.get("limit", Map.get(params, :limit, 100))
|
||||
|> Map.get("limit", 100)
|
||||
|> parse_limit(100)
|
||||
|> min(1000)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -837,40 +837,28 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
refute link_header =~ "since_id="
|
||||
end
|
||||
|
||||
test "lists accounts from and dismisses a notification group" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
|
||||
other_users = insert_list(9, :user)
|
||||
test "lists accounts from a notification group" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
|
||||
{:ok, status} = CommonAPI.post(user, %{status: "hello"})
|
||||
|
||||
Enum.each(other_users, fn other_user ->
|
||||
{:ok, _} = CommonAPI.favorite(status.id, other_user)
|
||||
end)
|
||||
|
||||
%{
|
||||
"notification_groups" => [
|
||||
%{
|
||||
"group_key" => group_key,
|
||||
"notifications_count" => 9,
|
||||
"sample_account_ids" => sample_account_ids
|
||||
}
|
||||
]
|
||||
} =
|
||||
conn
|
||||
|> get("/api/v2/notifications")
|
||||
|> json_response_and_validate_schema(200)
|
||||
{other_users, %{"group_key" => group_key, "sample_account_ids" => sample_account_ids}} =
|
||||
create_favourite_notification_group(user, conn)
|
||||
|
||||
assert length(sample_account_ids) == 8
|
||||
|
||||
%{conn: read_conn} = oauth_access(["read:notifications"], user: user)
|
||||
|
||||
account_ids =
|
||||
read_conn
|
||||
conn
|
||||
|> get("/api/v2/notifications/#{group_key}/accounts")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert Enum.sort(account_ids) == Enum.sort(Enum.map(other_users, & &1.id))
|
||||
end
|
||||
|
||||
test "dismisses a notification group" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
|
||||
|
||||
{_other_users, %{"group_key" => group_key}} =
|
||||
create_favourite_notification_group(user, conn)
|
||||
|
||||
assert %{} =
|
||||
conn
|
||||
|
|
@ -1012,6 +1000,29 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|> to_string()
|
||||
end
|
||||
|
||||
defp create_favourite_notification_group(user, conn) do
|
||||
other_users = insert_list(9, :user)
|
||||
|
||||
{:ok, status} = CommonAPI.post(user, %{status: "hello"})
|
||||
|
||||
Enum.each(other_users, fn other_user ->
|
||||
{:ok, _} = CommonAPI.favorite(status.id, other_user)
|
||||
end)
|
||||
|
||||
%{
|
||||
"notification_groups" => [
|
||||
%{
|
||||
"notifications_count" => 9
|
||||
} = group
|
||||
]
|
||||
} =
|
||||
conn
|
||||
|> get("/api/v2/notifications")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
{other_users, group}
|
||||
end
|
||||
|
||||
defp params_to_query(%{} = params) do
|
||||
Enum.map_join(params, "&", fn
|
||||
{k, v} when is_list(v) -> Enum.map_join(v, "&", &"#{k}[]=#{&1}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue