WebPush: Push out chat message notications.
authorlain <lain@soykaf.club>
Thu, 4 Jun 2020 12:49:10 +0000 (14:49 +0200)
committerlain <lain@soykaf.club>
Thu, 4 Jun 2020 12:49:10 +0000 (14:49 +0200)
lib/pleroma/web/push/impl.ex
lib/pleroma/web/push/subscription.ex
test/web/push/impl_test.exs

index 125f337558d6c7f15f4788458b17b1d631feeff5..006a242af275e39eeea307e68c6b5599b29397aa 100644 (file)
@@ -32,7 +32,7 @@ defmodule Pleroma.Web.Push.Impl do
     mastodon_type = notification.type
     gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
     avatar_url = User.avatar_url(actor)
-    object = Object.normalize(activity)
+    object = Object.normalize(activity, false)
     user = User.get_cached_by_id(user_id)
     direct_conversation_id = Activity.direct_conversation_id(activity, user)
 
@@ -171,6 +171,7 @@ defmodule Pleroma.Web.Push.Impl do
       "follow_request" -> "New Follow Request"
       "reblog" -> "New Repeat"
       "favourite" -> "New Favorite"
+      "pleroma:chat_mention" -> "New Chat Message"
       type -> "New #{String.capitalize(type || "event")}"
     end
   end
index 3e401a49026231941bb6583908ab0ce992ca12da..5b5aa0d597567fb80cf5521f66628d4e09d86fae 100644 (file)
@@ -25,7 +25,7 @@ defmodule Pleroma.Web.Push.Subscription do
     timestamps()
   end
 
-  @supported_alert_types ~w[follow favourite mention reblog]a
+  @supported_alert_types ~w[follow favourite mention reblog pleroma:chat_mention]a
 
   defp alerts(%{data: %{alerts: alerts}}) do
     alerts = Map.take(alerts, @supported_alert_types)
index 26c65bc8207c8b941b9708c931e82eda4c121382..8fb7faaa51f9aaa481e36af30a73765f26c7058a 100644 (file)
@@ -5,6 +5,7 @@
 defmodule Pleroma.Web.Push.ImplTest do
   use Pleroma.DataCase
 
+  alias Pleroma.Notification
   alias Pleroma.Object
   alias Pleroma.User
   alias Pleroma.Web.CommonAPI
@@ -196,6 +197,22 @@ defmodule Pleroma.Web.Push.ImplTest do
   end
 
   describe "build_content/3" do
+    test "builds content for chat messages" do
+      user = insert(:user)
+      recipient = insert(:user)
+
+      {:ok, chat} = CommonAPI.post_chat_message(user, recipient, "hey")
+      object = Object.normalize(chat, false)
+      [notification] = Notification.for_user(recipient)
+
+      res = Impl.build_content(notification, user, object)
+
+      assert res == %{
+               body: "@#{user.nickname}: hey",
+               title: "New Chat Message"
+             }
+    end
+
     test "hides details for notifications when privacy option enabled" do
       user = insert(:user, nickname: "Bob")
       user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true})