WebPush: Push out chat message notications.

This commit is contained in:
lain 2020-06-04 14:49:10 +02:00
parent 5d7dda883e
commit b952f3f379
3 changed files with 20 additions and 2 deletions

View file

@ -32,7 +32,7 @@ def perform(
mastodon_type = notification.type mastodon_type = notification.type
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key) gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
avatar_url = User.avatar_url(actor) avatar_url = User.avatar_url(actor)
object = Object.normalize(activity) object = Object.normalize(activity, false)
user = User.get_cached_by_id(user_id) user = User.get_cached_by_id(user_id)
direct_conversation_id = Activity.direct_conversation_id(activity, user) direct_conversation_id = Activity.direct_conversation_id(activity, user)
@ -171,6 +171,7 @@ def format_title(%{type: type}, mastodon_type) do
"follow_request" -> "New Follow Request" "follow_request" -> "New Follow Request"
"reblog" -> "New Repeat" "reblog" -> "New Repeat"
"favourite" -> "New Favorite" "favourite" -> "New Favorite"
"pleroma:chat_mention" -> "New Chat Message"
type -> "New #{String.capitalize(type || "event")}" type -> "New #{String.capitalize(type || "event")}"
end end
end end

View file

@ -25,7 +25,7 @@ defmodule Pleroma.Web.Push.Subscription do
timestamps() timestamps()
end 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 defp alerts(%{data: %{alerts: alerts}}) do
alerts = Map.take(alerts, @supported_alert_types) alerts = Map.take(alerts, @supported_alert_types)

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Web.Push.ImplTest do defmodule Pleroma.Web.Push.ImplTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Notification
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
@ -196,6 +197,22 @@ test "renders title for create activity with direct visibility" do
end end
describe "build_content/3" do 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 test "hides details for notifications when privacy option enabled" do
user = insert(:user, nickname: "Bob") user = insert(:user, nickname: "Bob")
user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true}) user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true})