Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
[akkoma] / lib / pleroma / notification.ex
index caa6b755e40027a0737d10e146babc0d6a7738c2..585157efece020946674f764f1adf9d49264b907 100644 (file)
@@ -33,6 +33,13 @@ defmodule Pleroma.Notification do
   def for_user_query(user) do
     Notification
     |> where(user_id: ^user.id)
+    |> where(
+      [n, a],
+      fragment(
+        "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')",
+        a.actor
+      )
+    )
     |> join(:inner, [n], activity in assoc(n, :activity))
     |> join(:left, [n, a], object in Object,
       on:
@@ -98,6 +105,14 @@ defmodule Pleroma.Notification do
     |> Repo.delete_all()
   end
 
+  def destroy_multiple(%{id: user_id} = _user, ids) do
+    from(n in Notification,
+      where: n.id in ^ids,
+      where: n.user_id == ^user_id
+    )
+    |> Repo.delete_all()
+  end
+
   def dismiss(%{id: user_id} = _user, id) do
     notification = Repo.get(Notification, id)
 
@@ -142,6 +157,7 @@ defmodule Pleroma.Notification do
       []
       |> Utils.maybe_notify_to_recipients(activity)
       |> Utils.maybe_notify_mentioned_recipients(activity)
+      |> Utils.maybe_notify_subscribers(activity)
       |> Enum.uniq()
 
     User.get_users_from_set(recipients, local_only)
@@ -163,19 +179,16 @@ defmodule Pleroma.Notification do
     User.blocks?(user, %{ap_id: actor})
   end
 
-  def skip?(:local, %{local: true}, user) do
-    user.info.notification_settings["local"] == false
-  end
+  def skip?(:local, %{local: true}, %{info: %{notification_settings: %{"local" => false}}}),
+    do: true
 
-  def skip?(:local, %{local: false}, user) do
-    user.info.notification_settings["remote"] == false
-  end
+  def skip?(:local, %{local: false}, %{info: %{notification_settings: %{"remote" => false}}}),
+    do: true
 
   def skip?(:muted, activity, user) do
     actor = activity.data["actor"]
 
-    User.mutes?(user, %{ap_id: actor}) or
-      CommonAPI.thread_muted?(user, activity)
+    User.mutes?(user, %{ap_id: actor}) or CommonAPI.thread_muted?(user, activity)
   end
 
   def skip?(
@@ -194,7 +207,7 @@ defmodule Pleroma.Notification do
     User.following?(user, followed)
   end
 
-  def skip?(:recently_followed, activity, user) do
+  def skip?(:recently_followed, %{data: %{"type" => "Follow"}} = activity, user) do
     actor = activity.data["actor"]
 
     Notification.for_user(user)