Handle "users/:id" links as well. Fix comments in MR.
[akkoma] / lib / pleroma / web / push / push.ex
index d27750ab67b18dc5542da322550e5107dbe48b02..5a873ec19cf3231c4079ef731e71c7525ce983b9 100644 (file)
@@ -18,11 +18,11 @@ defmodule Pleroma.Web.Push do
   def init(:ok) do
     case Application.get_env(:web_push_encryption, :vapid_details) do
       nil ->
-        Logger.error(
+        Logger.warn(
           "VAPID key pair is not found. Please, add VAPID configuration to config. Run `mix web_push.gen.keypair` mix task to create a key pair"
         )
 
-        {:error, %{}}
+        :ignore
 
       _ ->
         {:ok, %{}}
@@ -30,7 +30,9 @@ defmodule Pleroma.Web.Push do
   end
 
   def send(notification) do
-    GenServer.cast(Pleroma.Web.Push, {:send, notification})
+    if Application.get_env(:web_push_encryption, :vapid_details) do
+      GenServer.cast(Pleroma.Web.Push, {:send, notification})
+    end
   end
 
   def handle_cast(
@@ -66,9 +68,8 @@ defmodule Pleroma.Web.Push do
           Logger.error("Web Push Nonification failed with code: #{code}")
           :error
 
-        data ->
+        _ ->
           Logger.error("Web Push Nonification failed with unknown error")
-          IO.inspect(data)
           :error
       end
     end)
@@ -85,7 +86,7 @@ defmodule Pleroma.Web.Push do
     %{
       title: "New Mention",
       body: "@#{actor.nickname} has mentiond you",
-      icon: get_avatar_url(actor)
+      icon: User.avatar_url(actor)
     }
   end
 
@@ -93,7 +94,7 @@ defmodule Pleroma.Web.Push do
     %{
       title: "New Follower",
       body: "@#{actor.nickname} has followed you",
-      icon: get_avatar_url(actor)
+      icon: User.avatar_url(actor)
     }
   end
 
@@ -101,7 +102,7 @@ defmodule Pleroma.Web.Push do
     %{
       title: "New Announce",
       body: "@#{actor.nickname} has announced your post",
-      icon: get_avatar_url(actor)
+      icon: User.avatar_url(actor)
     }
   end
 
@@ -109,18 +110,7 @@ defmodule Pleroma.Web.Push do
     %{
       title: "New Like",
       body: "@#{actor.nickname} has liked your post",
-      icon: get_avatar_url(actor)
+      icon: User.avatar_url(actor)
     }
   end
-
-  def get_avatar_url(%{avatar: %{"type" => "Image", "url" => urls}}) do
-    case List.first(urls) do
-      %{"href" => url} -> url
-      _ -> get_avatar_url(nil)
-    end
-  end
-
-  def get_avatar_url(_) do
-    Pleroma.Web.Endpoint.static_url() <> "/images/avi.png"
-  end
 end