Merge branch 'develop' into 'domain-block-precedence'
authorSadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 10 Dec 2019 16:54:25 +0000 (16:54 +0000)
committerSadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 10 Dec 2019 16:54:25 +0000 (16:54 +0000)
# Conflicts:
#   lib/pleroma/user.ex

1  2 
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
test/user_test.exs
test/web/activity_pub/activity_pub_test.exs

index 601aa9cf04963c50e2d448f3323850c903dd7954,6b556e8e18727003b83a30827724d881fa86d10f..cebadc8ab0c8f830d0cb063242114deb5fd3faff
@@@ -1023,21 -1130,20 +1137,21 @@@ defmodule Pleroma.User d
    @spec muted_notifications?(User.t() | nil, User.t() | map()) :: boolean()
    def muted_notifications?(nil, _), do: false
  
-   def muted_notifications?(user, %{ap_id: ap_id}),
-     do: Enum.member?(user.muted_notifications, ap_id)
+   def muted_notifications?(%User{} = user, %User{} = target),
+     do: UserRelationship.notification_mute_exists?(user, target)
+   def blocks?(nil, _), do: false
  
    def blocks?(%User{} = user, %User{} = target) do
 -    blocks_user?(user, target) || blocks_domain?(user, target)
 +    blocks_ap_id?(user, target) ||
 +      (!User.following?(user, target) && blocks_domain?(user, target))
    end
  
-   def blocks?(nil, _), do: false
-   def blocks_ap_id?(%User{} = user, %User{} = target) do
-     Enum.member?(user.blocks, target.ap_id)
+   def blocks_user?(%User{} = user, %User{} = target) do
+     UserRelationship.block_exists?(user, target)
    end
  
-   def blocks_ap_id?(_, _), do: false
+   def blocks_user?(_, _), do: false
  
    def blocks_domain?(%User{} = user, %User{} = target) do
      domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
index 29cc1a17bb515e1bb33fa28eb9ee165d1b9c8b2c,6571102a96e9738b5c88eb5e64f036c865b7eeaf..c6744e5f254b1bda132a4d3db8eb51babc8d9de6
@@@ -912,14 -946,10 +946,14 @@@ defmodule Pleroma.Web.ActivityPub.Activ
  
    defp restrict_muted(query, _), do: query
  
-   defp restrict_blocked(query, %{"blocking_user" => %User{} = user}) do
-     blocks = user.blocks || []
+   defp restrict_blocked(query, %{"blocking_user" => %User{} = user} = opts) do
+     blocked_ap_ids = opts["blocked_users_ap_ids"] || User.blocked_users_ap_ids(user)
      domain_blocks = user.domain_blocks || []
  
 +    following_ap_ids =
 +      user
 +      |> User.get_friends_ap_ids()
 +
      query =
        if has_named_binding?(query, :object), do: query, else: Activity.with_joined_object(query)
  
            "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
            activity.data,
            activity.data,
-           ^blocks
+           ^blocked_ap_ids
          ),
 -      where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks),
 -      where: fragment("not (split_part(?->>'actor', '/', 3) = ANY(?))", o.data, ^domain_blocks)
 +      where:
 +        fragment(
 +          "(not (split_part(?, '/', 3) = ANY(?))) or ? = ANY(?)",
 +          activity.actor,
 +          ^domain_blocks,
 +          activity.actor,
 +          ^following_ap_ids
 +        ),
 +      where:
 +        fragment(
 +          "(not (split_part(?->>'actor', '/', 3) = ANY(?))) or (?->>'actor') = ANY(?)",
 +          o.data,
 +          ^domain_blocks,
 +          o.data,
 +          ^following_ap_ids
 +        )
      )
    end
  
Simple merge