WebPush: Don't break on contentless chat messages.
This commit is contained in:
parent
f24d2f714f
commit
4e8c0eecd5
|
@ -124,6 +124,13 @@ def build_content(notification, actor, object, mastodon_type) do
|
||||||
|
|
||||||
def format_body(activity, actor, object, mastodon_type \\ nil)
|
def format_body(activity, actor, object, mastodon_type \\ nil)
|
||||||
|
|
||||||
|
def format_body(_activity, actor, %{data: %{"type" => "ChatMessage", "content" => content}}, _) do
|
||||||
|
case content do
|
||||||
|
nil -> "@#{actor.nickname}: (Attachment)"
|
||||||
|
content -> "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => "Create"}}},
|
%{activity: %{data: %{"type" => "Create"}}},
|
||||||
actor,
|
actor,
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.Push.ImplTest do
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.Push.Impl
|
alias Pleroma.Web.Push.Impl
|
||||||
alias Pleroma.Web.Push.Subscription
|
alias Pleroma.Web.Push.Subscription
|
||||||
|
@ -213,6 +214,30 @@ test "builds content for chat messages" do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "builds content for chat messages with no content" do
|
||||||
|
user = insert(:user)
|
||||||
|
recipient = insert(:user)
|
||||||
|
|
||||||
|
file = %Plug.Upload{
|
||||||
|
content_type: "image/jpg",
|
||||||
|
path: Path.absname("test/fixtures/image.jpg"),
|
||||||
|
filename: "an_image.jpg"
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
|
{:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id)
|
||||||
|
object = Object.normalize(chat, false)
|
||||||
|
[notification] = Notification.for_user(recipient)
|
||||||
|
|
||||||
|
res = Impl.build_content(notification, user, object)
|
||||||
|
|
||||||
|
assert res == %{
|
||||||
|
body: "@#{user.nickname}: (Attachment)",
|
||||||
|
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})
|
||||||
|
|
Loading…
Reference in New Issue