+
+ @spec skip?(Activity.t(), User.t()) :: boolean()
+ def skip?(activity, user) do
+ [
+ :self,
+ :followers,
+ :follows,
+ :non_followers,
+ :non_follows,
+ :recently_followed
+ ]
+ |> Enum.any?(&skip?(&1, activity, user))
+ end
+
+ @spec skip?(atom(), Activity.t(), User.t()) :: boolean()
+ def skip?(:self, activity, user) do
+ activity.data["actor"] == user.ap_id
+ end
+
+ def skip?(
+ :followers,
+ activity,
+ %{info: %{notification_settings: %{"followers" => false}}} = user
+ ) do
+ actor = activity.data["actor"]
+ follower = User.get_cached_by_ap_id(actor)
+ User.following?(follower, user)
+ end
+
+ def skip?(
+ :non_followers,
+ activity,
+ %{info: %{notification_settings: %{"non_followers" => false}}} = user
+ ) do
+ actor = activity.data["actor"]
+ follower = User.get_cached_by_ap_id(actor)
+ !User.following?(follower, user)
+ end
+
+ def skip?(:follows, activity, %{info: %{notification_settings: %{"follows" => 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,
+ %{info: %{notification_settings: %{"non_follows" => false}}} = user
+ ) do
+ actor = activity.data["actor"]
+ followed = User.get_cached_by_ap_id(actor)
+ !User.following?(user, followed)
+ end
+
+ def skip?(:recently_followed, %{data: %{"type" => "Follow"}} = activity, user) do
+ actor = activity.data["actor"]
+
+ Notification.for_user(user)
+ |> Enum.any?(fn
+ %{activity: %{data: %{"type" => "Follow", "actor" => ^actor}}} -> true
+ _ -> false
+ end)
+ end
+
+ def skip?(_, _, _), do: false