diff options
| author | Sergey Suprunenko <suprunenko.s@gmail.com> | 2019-11-22 19:52:50 +0100 | 
|---|---|---|
| committer | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2020-07-06 09:28:22 +0300 | 
| commit | 5af1bf443dfd21a6b0be9efc1f55a73e590f6ba3 (patch) | |
| tree | d7e5766a8adda68a088854cd796b0d6045075d33 /lib | |
| parent | 4a8c26654eb7ca7ce049dd4c485c16672b5837a6 (diff) | |
| download | pleroma-5af1bf443dfd21a6b0be9efc1f55a73e590f6ba3.tar.gz pleroma-5af1bf443dfd21a6b0be9efc1f55a73e590f6ba3.zip | |
Skip notifications for statuses that contain an irreversible filtered word
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/notification.ex | 36 | 
1 files changed, 35 insertions, 1 deletions
| diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 2ef1a80c5..3f749cace 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -130,6 +130,7 @@ defmodule Pleroma.Notification do      |> preload([n, a, o], activity: {a, object: o})      |> exclude_notification_muted(user, exclude_notification_muted_opts)      |> exclude_blocked(user, exclude_blocked_opts) +    |> exclude_filtered(user)      |> exclude_visibility(opts)    end @@ -158,6 +159,20 @@ defmodule Pleroma.Notification do      |> where([n, a, o, tm], is_nil(tm.user_id))    end +  defp exclude_filtered(query, user) do +    case Pleroma.Filter.compose_regex(user) do +      nil -> +        query + +      regex -> +        from([_n, a, o] in query, +          where: +            fragment("not(?->>'content' ~* ?)", o.data, ^regex) or +              fragment("?->>'actor' = ?", o.data, ^user.ap_id) +        ) +    end +  end +    @valid_visibilities ~w[direct unlisted public private]    defp exclude_visibility(query, %{exclude_visibilities: visibility}) @@ -555,7 +570,8 @@ defmodule Pleroma.Notification do        :follows,        :non_followers,        :non_follows, -      :recently_followed +      :recently_followed, +      :filtered      ]      |> Enum.find(&skip?(&1, activity, user))    end @@ -624,6 +640,24 @@ defmodule Pleroma.Notification do      end)    end +  def skip?(:filtered, activity, user) do +    object = Object.normalize(activity) + +    cond do +      is_nil(object) -> +        false + +      object.data["actor"] == user.ap_id -> +        false + +      not is_nil(regex = Pleroma.Filter.compose_regex(user, :re)) -> +        Regex.match?(regex, object.data["content"]) + +      true -> +        false +    end +  end +    def skip?(_, _, _), do: false    def for_user_and_activity(user, activity) do | 
