Change mobile new comment notification text and add sound (#14678)
This commit is contained in:
parent
0aa27f3d1e
commit
ed1731fd95
3 changed files with 31 additions and 4 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue