Change mobile new comment notification text and add sound (#14678)

This commit is contained in:
Josh Puetz 2021-09-13 11:15:58 -05:00 committed by GitHub
parent 0aa27f3d1e
commit ed1731fd95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 4 deletions

View file

@ -38,9 +38,10 @@ class Device < ApplicationRecord
alert: {
title: Settings::Community.community_name,
subtitle: title,
body: body
body: body.truncate(512)
},
"thread-id": Settings::Community.community_name
"thread-id": Settings::Community.community_name,
sound: "default"
},
data: payload
}

View file

@ -3,6 +3,8 @@
module Notifications
module NewComment
class Send
include ActionView::Helpers::TextHelper
def initialize(comment)
@comment = comment
end
@ -40,8 +42,10 @@ module Notifications
PushNotifications::Send.call(
user_ids: targets,
title: "@#{comment.user.username}",
body: "Re: #{comment.parent_or_root_article.title.strip}",
title: "💬 New Comment",
body: "#{comment.user.username} commented on " \
"#{comment.commentable.title.strip}:\n" \
"#{strip_tags(comment.processed_html).strip}",
payload: {
url: URL.url(comment.path),
type: "new comment"

View file

@ -2,6 +2,7 @@ require "rails_helper"
RSpec.describe Device, type: :model do
let(:device) { create(:device) }
let(:user) { create(:user) }
describe "validations" do
subject { device }
@ -14,4 +15,25 @@ RSpec.describe Device, type: :model do
it { is_expected.to validate_uniqueness_of(:token).scoped_to(%i[user_id platform consumer_app_id]) }
end
end
describe "#create_notification" do
let(:data_hash) { { "alert" => "Hello World" } }
context "when iOS device" do
let(:consumer_app_ios) { create(:consumer_app, platform: :ios) }
it "creates an Apns2 notification" do
mocked_objects = mock_rpush(consumer_app_ios)
device = create(:device, user: user, platform: "iOS")
device.create_notification("Subtitle", "Body", data_hash)
expect(mocked_objects[:rpush_notification].data[:aps][:alert][:title]).to eq(Settings::Community.community_name)
expect(mocked_objects[:rpush_notification].data[:aps][:alert][:subtitle]).to eq("Subtitle")
expect(mocked_objects[:rpush_notification].data[:aps][:alert][:body]).to eq("Body")
expect(mocked_objects[:rpush_notification].data[:aps][:"thread-id"]).to eq(Settings::Community.community_name)
expect(mocked_objects[:rpush_notification].data[:aps][:sound]).to eq("default")
expect(mocked_objects[:rpush_notification].data[:data]).to eq(data_hash)
end
end
end
end