+ |> exclude_notification_muted(user, exclude_notification_muted_opts)
+ |> exclude_blocked(user, exclude_blocked_opts)
+ |> exclude_visibility(opts)
+ |> exclude_move(opts)
+ end
+
+ defp exclude_blocked(query, user, opts) do
+ blocked_ap_ids = opts[:blocked_users_ap_ids] || User.blocked_users_ap_ids(user)
+
+ query
+ |> where([n, a], a.actor not in ^blocked_ap_ids)
+ |> where(
+ [n, a],
+ fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.domain_blocks
+ )
+ end
+
+ defp exclude_notification_muted(query, _, %{@include_muted_option => true}) do
+ query
+ end
+
+ defp exclude_notification_muted(query, user, opts) do
+ notification_muted_ap_ids =
+ opts[:notification_muted_users_ap_ids] || User.notification_muted_users_ap_ids(user)
+
+ query
+ |> where([n, a], a.actor not in ^notification_muted_ap_ids)
+ |> join(:left, [n, a], tm in Pleroma.ThreadMute,
+ on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data)
+ )
+ |> where([n, a, o, tm], is_nil(tm.user_id))
+ end
+
+ defp exclude_move(query, %{with_move: true}) do
+ query