Merge branch 'feature/move-activity' into 'develop'
[akkoma] / lib / pleroma / web / push / impl.ex
index 7ea5607faaa896b6ca476835da4ea9e1772dad8c..a6a924d02f067191ddda7e157ffbb40209fd2f12 100644 (file)
@@ -9,7 +9,6 @@ defmodule Pleroma.Web.Push.Impl do
   alias Pleroma.Notification
   alias Pleroma.Object
   alias Pleroma.Repo
-  alias Pleroma.SubscriptionNotification
   alias Pleroma.User
   alias Pleroma.Web.Metadata.Utils
   alias Pleroma.Web.Push.Subscription
@@ -17,10 +16,10 @@ defmodule Pleroma.Web.Push.Impl do
   require Logger
   import Ecto.Query
 
-  @types ["Create", "Follow", "Announce", "Like"]
+  @types ["Create", "Follow", "Announce", "Like", "Move"]
 
   @doc "Performs sending notifications for user subscriptions"
-  @spec perform(Notification.t() | SubscriptionNotification.t()) :: list(any) | :error
+  @spec perform(Notification.t()) :: list(any) | :error
   def perform(
         %{
           activity: %{data: %{"type" => activity_type}, id: activity_id} = activity,
@@ -34,6 +33,8 @@ defmodule Pleroma.Web.Push.Impl do
     gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
     avatar_url = User.avatar_url(actor)
     object = Object.normalize(activity)
+    user = User.get_cached_by_id(user_id)
+    direct_conversation_id = Activity.direct_conversation_id(activity, user)
 
     for subscription <- fetch_subsriptions(user_id),
         get_in(subscription.data, ["alerts", type]) do
@@ -46,7 +47,8 @@ defmodule Pleroma.Web.Push.Impl do
         icon: avatar_url,
         preferred_locale: "en",
         pleroma: %{
-          activity_id: activity_id
+          activity_id: activity_id,
+          direct_conversation_id: direct_conversation_id
         }
       }
       |> Jason.encode!()
@@ -126,6 +128,10 @@ defmodule Pleroma.Web.Push.Impl do
     end
   end
 
+  def format_title(%{activity: %{data: %{"directMessage" => true}}}) do
+    "New Direct Message"
+  end
+
   def format_title(%{activity: %{data: %{"type" => type}}}) do
     case type do
       "Create" -> "New Mention"