From fd5e797379155e5a85deb88dc79f8fbca483948e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jun 2020 11:24:28 -0500 Subject: Simplify notification filtering settings further --- lib/pleroma/notification.ex | 28 +++------------------------- lib/pleroma/user/notification_setting.ex | 8 ++------ lib/pleroma/web/api_spec/schemas/account.ex | 8 ++------ 3 files changed, 7 insertions(+), 37 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 9d09cf082..8a28a1821 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -550,9 +550,7 @@ defmodule Pleroma.Notification do [ :self, :invisible, - :from_followers, - :from_following, - :from_strangers, + :block_from_strangers, :recently_followed ] |> Enum.find(&skip?(&1, activity, user)) @@ -572,35 +570,15 @@ defmodule Pleroma.Notification do end def skip?( - :from_followers, + :block_from_strangers, %Activity{} = activity, - %User{notification_settings: %{from_followers: false}} = user - ) do - actor = activity.data["actor"] - follower = User.get_cached_by_ap_id(actor) - User.following?(follower, user) - end - - def skip?( - :from_strangers, - %Activity{} = activity, - %User{notification_settings: %{from_strangers: false}} = user + %User{notification_settings: %{block_from_strangers: true}} = user ) do actor = activity.data["actor"] follower = User.get_cached_by_ap_id(actor) !User.following?(follower, user) end - def skip?( - :from_following, - %Activity{} = activity, - %User{notification_settings: %{from_following: false}} = user - ) do - actor = activity.data["actor"] - followed = User.get_cached_by_ap_id(actor) - User.following?(user, followed) - end - # To do: consider defining recency in hours and checking FollowingRelationship with a single SQL def skip?(:recently_followed, %Activity{data: %{"type" => "Follow"}} = activity, %User{} = user) do actor = activity.data["actor"] diff --git a/lib/pleroma/user/notification_setting.ex b/lib/pleroma/user/notification_setting.ex index e47ac4cab..ffe9860de 100644 --- a/lib/pleroma/user/notification_setting.ex +++ b/lib/pleroma/user/notification_setting.ex @@ -10,18 +10,14 @@ defmodule Pleroma.User.NotificationSetting do @primary_key false embedded_schema do - field(:from_followers, :boolean, default: true) - field(:from_following, :boolean, default: true) - field(:from_strangers, :boolean, default: true) + field(:block_from_strangers, :boolean, default: false) field(:privacy_option, :boolean, default: false) end def changeset(schema, params) do schema |> cast(prepare_attrs(params), [ - :from_followers, - :from_following, - :from_strangers, + :block_from_strangers, :privacy_option ]) end diff --git a/lib/pleroma/web/api_spec/schemas/account.ex b/lib/pleroma/web/api_spec/schemas/account.ex index ed90ef3db..91bb1ba88 100644 --- a/lib/pleroma/web/api_spec/schemas/account.ex +++ b/lib/pleroma/web/api_spec/schemas/account.ex @@ -57,9 +57,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do notification_settings: %Schema{ type: :object, properties: %{ - from_followers: %Schema{type: :boolean}, - from_following: %Schema{type: :boolean}, - from_strangers: %Schema{type: :boolean}, + block_from_strangers: %Schema{type: :boolean}, privacy_option: %Schema{type: :boolean} } }, @@ -122,9 +120,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do "unread_conversation_count" => 0, "tags" => [], "notification_settings" => %{ - "from_followers" => true, - "from_following" => true, - "from_strangers" => true, + "block_from_strangers" => false, "privacy_option" => false }, "relationship" => %{ -- cgit v1.2.3