diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/notification.ex | 12 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 44 | 
2 files changed, 54 insertions, 2 deletions
| diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 7efbdc49a..4cc9a5669 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -127,6 +127,7 @@ defmodule Pleroma.Notification do      |> where([user_actor: user_actor], user_actor.is_active)      |> exclude_notification_muted(user, exclude_notification_muted_opts)      |> exclude_blocked(user, exclude_blocked_opts) +    |> exclude_blockers(user)      |> exclude_filtered(user)      |> exclude_visibility(opts)    end @@ -140,6 +141,17 @@ defmodule Pleroma.Notification do      |> FollowingRelationship.keep_following_or_not_domain_blocked(user)    end +  defp exclude_blockers(query, user) do +    if Pleroma.Config.get([:activitypub, :blockers_visible]) == true do +      query +    else +      blocker_ap_ids = User.incoming_relationships_ungrouped_ap_ids(user, [:block]) + +      query +      |> where([n, a], a.actor not in ^blocker_ap_ids) +    end +  end +    defp exclude_notification_muted(query, _, %{@include_muted_option => true}) do      query    end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index d0051d1cb..a35ba1fad 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -431,6 +431,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do      |> maybe_preload_bookmarks(opts)      |> maybe_set_thread_muted_field(opts)      |> restrict_blocked(opts) +    |> restrict_blockers_visibility(opts)      |> restrict_recipients(recipients, opts[:user])      |> restrict_filtered(opts)      |> where( @@ -1018,7 +1019,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do      from(        [activity, object: o] in query, +      # You don't block the author        where: fragment("not (? = ANY(?))", activity.actor, ^blocked_ap_ids), + +      # You don't block any recipients, and didn't author the post        where:          fragment(            "((not (? && ?)) or ? = ?)", @@ -1027,12 +1031,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do            activity.actor,            ^user.ap_id          ), + +      # You don't block the domain of any recipients, and didn't author the post        where:          fragment( -          "recipients_contain_blocked_domains(?, ?) = false", +          "(recipients_contain_blocked_domains(?, ?) = false) or ? = ?",            activity.recipients, -          ^domain_blocks +          ^domain_blocks, +          activity.actor, +          ^user.ap_id          ), + +      # It's not a boost of a user you block        where:          fragment(            "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)", @@ -1040,6 +1050,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do            activity.data,            ^blocked_ap_ids          ), + +      # You don't block the author's domain, and also don't follow the author        where:          fragment(            "(not (split_part(?, '/', 3) = ANY(?))) or ? = ANY(?)", @@ -1048,6 +1060,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do            activity.actor,            ^following_ap_ids          ), + +      # Same as above, but checks the Object        where:          fragment(            "(not (split_part(?->>'actor', '/', 3) = ANY(?))) or (?->>'actor') = ANY(?)", @@ -1061,6 +1075,31 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do    defp restrict_blocked(query, _), do: query +  defp restrict_blockers_visibility(query, %{blocking_user: %User{} = user}) do +    if Config.get([:activitypub, :blockers_visible]) == true do +      query +    else +      blocker_ap_ids = User.incoming_relationships_ungrouped_ap_ids(user, [:block]) + +      from( +        activity in query, +        # The author doesn't block you +        where: fragment("not (? = ANY(?))", activity.actor, ^blocker_ap_ids), + +        # It's not a boost of a user that blocks you +        where: +          fragment( +            "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)", +            activity.data, +            activity.data, +            ^blocker_ap_ids +          ) +      ) +    end +  end + +  defp restrict_blockers_visibility(query, _), do: query +    defp restrict_unlisted(query, %{restrict_unlisted: true}) do      from(        activity in query, @@ -1287,6 +1326,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do        |> restrict_state(opts)        |> restrict_favorited_by(opts)        |> restrict_blocked(restrict_blocked_opts) +      |> restrict_blockers_visibility(opts)        |> restrict_muted(restrict_muted_opts)        |> restrict_filtered(opts)        |> restrict_media(opts) | 
