Refactor notification settings
[akkoma] / lib / pleroma / notification.ex
index fb16ec8967efa82c55950208e9c2aaab65381d99..ca556f0bbc5d4498cd8afbe0b9a6fcd32f88f70e 100644 (file)
@@ -361,7 +361,8 @@ defmodule Pleroma.Notification do
       when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReact"] do
     potential_receiver_ap_ids = get_potential_receiver_ap_ids(activity)
 
-    potential_receivers = User.get_users_from_set(potential_receiver_ap_ids, local_only)
+    potential_receivers =
+      User.get_users_from_set(potential_receiver_ap_ids, local_only: local_only)
 
     notification_enabled_ap_ids =
       potential_receiver_ap_ids
@@ -458,10 +459,9 @@ defmodule Pleroma.Notification do
   def skip?(%Activity{} = activity, %User{} = user) do
     [
       :self,
-      :followers,
-      :follows,
-      :non_followers,
-      :non_follows,
+      :from_followers,
+      :from_following,
+      :from_strangers,
       :recently_followed
     ]
     |> Enum.find(&skip?(&1, activity, user))
@@ -475,9 +475,9 @@ defmodule Pleroma.Notification do
   end
 
   def skip?(
-        :followers,
+        :from_followers,
         %Activity{} = activity,
-        %User{notification_settings: %{followers: false}} = user
+        %User{notification_settings: %{from_followers: false}} = user
       ) do
     actor = activity.data["actor"]
     follower = User.get_cached_by_ap_id(actor)
@@ -485,9 +485,9 @@ defmodule Pleroma.Notification do
   end
 
   def skip?(
-        :non_followers,
+        :from_strangers,
         %Activity{} = activity,
-        %User{notification_settings: %{non_followers: false}} = user
+        %User{notification_settings: %{from_strangers: false}} = user
       ) do
     actor = activity.data["actor"]
     follower = User.get_cached_by_ap_id(actor)
@@ -495,25 +495,15 @@ defmodule Pleroma.Notification do
   end
 
   def skip?(
-        :follows,
+        :from_following,
         %Activity{} = activity,
-        %User{notification_settings: %{follows: false}} = user
+        %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
 
-  def skip?(
-        :non_follows,
-        %Activity{} = activity,
-        %User{notification_settings: %{non_follows: 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"]