activitypub: utils: update the state of *any* pending follow relationship that matche...
[akkoma] / lib / pleroma / web / push / push.ex
index 35e14c243d984283e1c6eadd57f4e2c3810b5137..ffd2aac91ad1097de63be3c229eb94a72f1e3028 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Web.Push do
   use GenServer
 
 defmodule Pleroma.Web.Push do
   use GenServer
 
@@ -32,7 +36,7 @@ defmodule Pleroma.Web.Push do
   end
 
   def init(:ok) do
   end
 
   def init(:ok) do
-    if enabled() do
+    if !enabled() do
       Logger.warn("""
       VAPID key pair is not found. If you wish to enabled web push, please run
 
       Logger.warn("""
       VAPID key pair is not found. If you wish to enabled web push, please run
 
@@ -54,7 +58,7 @@ defmodule Pleroma.Web.Push do
       when type in @types do
     actor = User.get_cached_by_ap_id(notification.activity.data["actor"])
 
       when type in @types do
     actor = User.get_cached_by_ap_id(notification.activity.data["actor"])
 
-    type = format_type(notification)
+    type = Pleroma.Activity.mastodon_notification_type(notification.activity)
 
     Subscription
     |> where(user_id: ^user_id)
 
     Subscription
     |> where(user_id: ^user_id)
@@ -114,16 +118,6 @@ defmodule Pleroma.Web.Push do
     {:noreply, state}
   end
 
     {:noreply, state}
   end
 
-  # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
-  defp format_type(%{activity: %{data: %{"type" => type}}}) do
-    case type do
-      "Create" -> "mention"
-      "Follow" -> "follow"
-      "Announce" -> "reblog"
-      "Like" -> "favourite"
-    end
-  end
-
   defp format_title(%{activity: %{data: %{"type" => type}}}) do
     case type do
       "Create" -> "New Mention"
   defp format_title(%{activity: %{data: %{"type" => type}}}) do
     case type do
       "Create" -> "New Mention"