From f1781c14eb8b0b66240095e0393b0c9bfb01a301 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 20 Nov 2020 10:33:27 +0300 Subject: [PATCH] fixes after rebase --- lib/pleroma/notification.ex | 46 +++++++++++----------- .../controllers/notification_controller.ex | 2 +- .../web/mastodon_api/masto_fe_controller_test.exs | 1 - .../web/mastodon_api/views/account_view_test.exs | 2 +- .../web/twitter_api/util_controller_test.exs | 5 +-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 78dd97513..c3d20aa9f 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -5,6 +5,9 @@ defmodule Pleroma.Notification do use Ecto.Schema + import Ecto.Query + import Ecto.Changeset + alias Ecto.Multi alias Pleroma.Activity alias Pleroma.FollowingRelationship @@ -20,15 +23,26 @@ defmodule Pleroma.Notification do alias Pleroma.Web.Push alias Pleroma.Web.Streamer - import Ecto.Query - import Ecto.Changeset - require Logger - @type t :: %__MODULE__{} - @include_muted_option :with_muted + @types ~w{ + favourite + follow + follow_request + mention + move + pleroma:chat_mention + pleroma:emoji_reaction + pleroma:report + reblog + } + + @types_excluding_chat_and_report @types -- ~w(pleroma:chat_mention pleroma:report) + + @type t :: %__MODULE__{} + schema "notifications" do field(:seen, :boolean, default: false) # This is an enum type in the database. If you add a new notification type, @@ -62,28 +76,16 @@ defmodule Pleroma.Notification do |> Repo.aggregate(:count, :id) end - @notification_types ~w{ - favourite - follow - follow_request - mention - move - pleroma:chat_mention - pleroma:emoji_reaction - pleroma:report - reblog - } + @spec types() :: [String.t()] + def types, do: @types - @notification_types_excluding_chat List.delete(@notification_types, "pleroma:chat_mention") - - def types, do: @notification_types - - def types_excluding_chat, do: @notification_types_excluding_chat + @spec types_excluding_chat_and_report() :: [String.t()] + def types_excluding_chat_and_report, do: @types_excluding_chat_and_report def changeset(%Notification{} = notification, attrs) do notification |> cast(attrs, [:seen, :type]) - |> validate_inclusion(:type, @notification_types) + |> validate_inclusion(:type, @types) end @spec last_read_query(User.t()) :: Ecto.Queryable.t() diff --git a/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex b/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex index e6e893680..771280a81 100644 --- a/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex @@ -46,7 +46,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do params = params |> Map.new(fn {k, v} -> {to_string(k), v} end) - |> Map.put_new("include_types", Pleroma.Notification.types_excluding_chat()) + |> Map.put_new("include_types", Pleroma.Notification.types_excluding_chat_and_report()) notifications = MastodonAPI.get_notifications(user, params) diff --git a/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs b/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs index f8e91aa05..2962b0bc4 100644 --- a/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs +++ b/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs @@ -24,7 +24,6 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do user = User.get_cached_by_ap_id(user.ap_id) assert user.mastofe_settings == %{"programming" => "socks"} - end end describe "index/2 redirections" do diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index a9c66e63e..1f5b99695 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -124,7 +124,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do notification_settings = %{ block_from_strangers: false, - hide_notification_contents: false + hide_notification_contents: false, followers: true, follows: true, non_followers: true, diff --git a/test/pleroma/web/twitter_api/util_controller_test.exs b/test/pleroma/web/twitter_api/util_controller_test.exs index f6a552369..4314efd34 100644 --- a/test/pleroma/web/twitter_api/util_controller_test.exs +++ b/test/pleroma/web/twitter_api/util_controller_test.exs @@ -27,9 +27,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn |> put("/api/pleroma/notification_settings", %{ "block_from_strangers" => true, - "bar" => 1 - "followers" => false, "bar" => 1, + "followers" => false, "exclude_types" => ["follow"] }) |> json_response(:ok) @@ -38,7 +37,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert %Pleroma.User.NotificationSetting{ block_from_strangers: true, - hide_notification_contents: false + hide_notification_contents: false, followers: false, follows: true, non_follows: true,