Merge branch 'develop' into 'fix/oauth-compile-time'
[akkoma] / lib / pleroma / notification.ex
index d4b6eb3b8c2ba72fae9900058af353e6d36cc166..71423ce5e89695175073e6d44d41bfaba56b5f88 100644 (file)
@@ -77,6 +77,7 @@ defmodule Pleroma.Notification do
     |> exclude_notification_muted(user, exclude_notification_muted_opts)
     |> exclude_blocked(user, exclude_blocked_opts)
     |> exclude_visibility(opts)
+    |> exclude_move(opts)
   end
 
   defp exclude_blocked(query, user, opts) do
@@ -106,6 +107,14 @@ defmodule Pleroma.Notification do
     |> where([n, a, o, tm], is_nil(tm.user_id))
   end
 
+  defp exclude_move(query, %{with_move: true}) do
+    query
+  end
+
+  defp exclude_move(query, _opts) do
+    where(query, [n, a], fragment("?->>'type' != 'Move'", a.data))
+  end
+
   @valid_visibilities ~w[direct unlisted public private]
 
   defp exclude_visibility(query, %{exclude_visibilities: visibility})
@@ -276,10 +285,13 @@ defmodule Pleroma.Notification do
     end
   end
 
-  def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity)
-      when type in ["Like", "Announce", "Follow"] do
-    users = get_notified_from_activity(activity)
-    notifications = Enum.map(users, fn user -> create_notification(activity, user) end)
+  def create_notifications(%Activity{data: %{"type" => type}} = activity)
+      when type in ["Like", "Announce", "Follow", "Move"] do
+    notifications =
+      activity
+      |> get_notified_from_activity()
+      |> Enum.map(&create_notification(activity, &1))
+
     {:ok, notifications}
   end
 
@@ -301,19 +313,15 @@ defmodule Pleroma.Notification do
 
   def get_notified_from_activity(activity, local_only \\ true)
 
-  def get_notified_from_activity(
-        %Activity{data: %{"to" => _, "type" => type} = _data} = activity,
-        local_only
-      )
-      when type in ["Create", "Like", "Announce", "Follow"] do
-    recipients =
-      []
-      |> 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)
+  def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
+      when type in ["Create", "Like", "Announce", "Follow", "Move"] do
+    []
+    |> Utils.maybe_notify_to_recipients(activity)
+    |> Utils.maybe_notify_mentioned_recipients(activity)
+    |> Utils.maybe_notify_subscribers(activity)
+    |> Utils.maybe_notify_followers(activity)
+    |> Enum.uniq()
+    |> User.get_users_from_set(local_only)
   end
 
   def get_notified_from_activity(_, _local_only), do: []