Simplify notification filtering settings further

This commit is contained in:
Mark Felder 2020-06-26 11:24:28 -05:00
commit fd5e797379
9 changed files with 15 additions and 123 deletions

View file

@ -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"]

View file

@ -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

View file

@ -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" => %{