+ potential_receiver_ap_ids =
+ []
+ |> Utils.maybe_notify_to_recipients(activity)
+ |> Utils.maybe_notify_mentioned_recipients(activity)
+ |> Utils.maybe_notify_subscribers(activity)
+ |> Utils.maybe_notify_followers(activity)
+ |> Enum.uniq()
+
+ potential_receivers = User.get_users_from_set(potential_receiver_ap_ids, local_only)
+
+ notification_enabled_ap_ids =
+ potential_receiver_ap_ids
+ |> exclude_domain_blocker_ap_ids(activity, potential_receivers)
+ |> exclude_relationship_restricted_ap_ids(activity)
+ |> exclude_thread_muter_ap_ids(activity)
+
+ notification_enabled_users =
+ Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end)
+
+ {notification_enabled_users, potential_receivers -- notification_enabled_users}
+ end
+
+ def get_notified_from_activity(_, _local_only), do: {[], []}
+
+ @doc "Filters out AP IDs domain-blocking and not following the activity's actor"
+ def exclude_domain_blocker_ap_ids(ap_ids, activity, preloaded_users \\ [])
+
+ def exclude_domain_blocker_ap_ids([], _activity, _preloaded_users), do: []
+
+ def exclude_domain_blocker_ap_ids(ap_ids, %Activity{} = activity, preloaded_users) do
+ activity_actor_domain = activity.actor && URI.parse(activity.actor).host
+
+ users =
+ ap_ids
+ |> Enum.map(fn ap_id ->
+ Enum.find(preloaded_users, &(&1.ap_id == ap_id)) ||
+ User.get_cached_by_ap_id(ap_id)
+ end)
+ |> Enum.filter(& &1)
+
+ domain_blocker_ap_ids = for u <- users, activity_actor_domain in u.domain_blocks, do: u.ap_id
+
+ domain_blocker_follower_ap_ids =
+ if Enum.any?(domain_blocker_ap_ids) do
+ activity
+ |> Activity.user_actor()
+ |> FollowingRelationship.followers_ap_ids(domain_blocker_ap_ids)
+ else
+ []
+ end
+
+ ap_ids
+ |> Kernel.--(domain_blocker_ap_ids)
+ |> Kernel.++(domain_blocker_follower_ap_ids)