X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fnotification.ex;h=60dba343497cd86545b37c204ace8d6e47b56739;hb=d88c8a9614808c00e25025fa70d9e1192bbbf89b;hp=71423ce5e89695175073e6d44d41bfaba56b5f88;hpb=8404f8c8fbc4a60473df0977bc05e2587207d811;p=akkoma
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 71423ce5e..60dba3434 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Notification do
@@ -121,10 +121,28 @@ defmodule Pleroma.Notification do
when is_list(visibility) do
if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
query
+ |> join(:left, [n, a], mutated_activity in Pleroma.Activity,
+ on:
+ fragment("?->>'context'", a.data) ==
+ fragment("?->>'context'", mutated_activity.data) and
+ fragment("(?->>'type' = 'Like' or ?->>'type' = 'Announce')", a.data, a.data) and
+ fragment("?->>'type'", mutated_activity.data) == "Create",
+ as: :mutated_activity
+ )
|> where(
- [n, a],
+ [n, a, mutated_activity: mutated_activity],
not fragment(
- "activity_visibility(?, ?, ?) = ANY (?)",
+ """
+ CASE WHEN (?->>'type') = 'Like' or (?->>'type') = 'Announce'
+ THEN (activity_visibility(?, ?, ?) = ANY (?))
+ ELSE (activity_visibility(?, ?, ?) = ANY (?)) END
+ """,
+ a.data,
+ a.data,
+ mutated_activity.actor,
+ mutated_activity.recipients,
+ mutated_activity.data,
+ ^visibility,
a.actor,
a.recipients,
a.data,
@@ -139,17 +157,7 @@ defmodule Pleroma.Notification do
defp exclude_visibility(query, %{exclude_visibilities: visibility})
when visibility in @valid_visibilities do
- query
- |> where(
- [n, a],
- not fragment(
- "activity_visibility(?, ?, ?) = (?)",
- a.actor,
- a.recipients,
- a.data,
- ^visibility
- )
- )
+ exclude_visibility(query, [visibility])
end
defp exclude_visibility(query, %{exclude_visibilities: visibility})
@@ -286,7 +294,7 @@ defmodule Pleroma.Notification do
end
def create_notifications(%Activity{data: %{"type" => type}} = activity)
- when type in ["Like", "Announce", "Follow", "Move"] do
+ when type in ["Like", "Announce", "Follow", "Move", "EmojiReact"] do
notifications =
activity
|> get_notified_from_activity()
@@ -314,7 +322,7 @@ defmodule Pleroma.Notification do
def get_notified_from_activity(activity, local_only \\ true)
def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
- when type in ["Create", "Like", "Announce", "Follow", "Move"] do
+ when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReact"] do
[]
|> Utils.maybe_notify_to_recipients(activity)
|> Utils.maybe_notify_mentioned_recipients(activity)
@@ -347,7 +355,7 @@ defmodule Pleroma.Notification do
def skip?(
:followers,
activity,
- %{notification_settings: %{"followers" => false}} = user
+ %{notification_settings: %{followers: false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
@@ -357,14 +365,14 @@ defmodule Pleroma.Notification do
def skip?(
:non_followers,
activity,
- %{notification_settings: %{"non_followers" => false}} = user
+ %{notification_settings: %{non_followers: false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
!User.following?(follower, user)
end
- def skip?(:follows, activity, %{notification_settings: %{"follows" => false}} = user) do
+ def skip?(:follows, activity, %{notification_settings: %{follows: false}} = user) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
@@ -373,7 +381,7 @@ defmodule Pleroma.Notification do
def skip?(
:non_follows,
activity,
- %{notification_settings: %{"non_follows" => false}} = user
+ %{notification_settings: %{non_follows: false}} = user
) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)