Add capability for emoji reaction push notifications
authorMark Felder <feld@FreeBSD.org>
Fri, 13 Nov 2020 23:01:53 +0000 (17:01 -0600)
committerMark Felder <feld@FreeBSD.org>
Tue, 17 Nov 2020 20:20:00 +0000 (20:20 +0000)
lib/pleroma/web/push/impl.ex
test/pleroma/web/push/impl_test.exs

index da535aa68bf93f0fd3e1edcc8335ad657c4059af..f91cb1d40718eabcebbceb57139935dcc30a2511 100644 (file)
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.Push.Impl do
   require Logger
   import Ecto.Query
 
-  @types ["Create", "Follow", "Announce", "Like", "Move"]
+  @types ["Create", "Follow", "Announce", "Like", "Move", "EmojiReact"]
 
   @doc "Performs sending notifications for user subscriptions"
   @spec perform(Notification.t()) :: list(any) | :error | {:error, :unknown_type}
@@ -149,6 +149,15 @@ defmodule Pleroma.Web.Push.Impl do
     "@#{actor.nickname} repeated: #{Utils.scrub_html_and_truncate(content, 80)}"
   end
 
+  def format_body(
+        %{activity: %{data: %{"type" => "EmojiReact", "content" => content}}},
+        actor,
+        _object,
+        _mastodon_type
+      ) do
+    "@#{actor.nickname} has reacted with #{content}"
+  end
+
   def format_body(
         %{activity: %{data: %{"type" => type}}} = notification,
         actor,
@@ -179,6 +188,7 @@ defmodule Pleroma.Web.Push.Impl do
       "reblog" -> "New Repeat"
       "favourite" -> "New Favorite"
       "pleroma:chat_mention" -> "New Chat Message"
+      "pleroma:emoji_reaction" -> "New Reaction"
       type -> "New #{String.capitalize(type || "event")}"
     end
   end
index 7d8cc999a9035faff4fb93977763650778a1cec8..2575c76d670c9cebca72c5d211f6c63c2638e838 100644 (file)
@@ -184,6 +184,24 @@ defmodule Pleroma.Web.Push.ImplTest do
              "New Favorite"
   end
 
+  test "renders title and body for pleroma:emoji_reaction activity" do
+    user = insert(:user, nickname: "Bob")
+
+    {:ok, activity} =
+      CommonAPI.post(user, %{
+        status: "This post is a really good post!"
+      })
+
+    {:ok, activity} = CommonAPI.react_with_emoji(activity.id, user, "👍")
+    object = Object.normalize(activity)
+
+    assert Impl.format_body(%{activity: activity, type: "pleroma:emoji_reaction"}, user, object) ==
+             "@Bob has reacted with 👍"
+
+    assert Impl.format_title(%{activity: activity, type: "pleroma:emoji_reaction"}) ==
+             "New Reaction"
+  end
+
   test "renders title for create activity with direct visibility" do
     user = insert(:user, nickname: "Bob")