mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:50:00 +08:00
7ba115769a
* DEV: Skip push notifications for active online users Currently, users with active push subscriptions get push notifications regardless of their "presence" on the site. This change introduces a `push_notification_time_window_mins` site setting which is used in conjunction with a user's `last_seen_at` to determine if push notifications should be sent. A user is considered to be actively online if their `last_seen_at` is within `push_notification_time_window_mins` minutes. `push_notification_time_window_mins` is set to 10 by default. * DEV: Remove client param for push_notification_time_window_mins site setting Co-authored-by: Bianca Nenciu <nbianca@users.noreply.github.com> Co-authored-by: Bianca Nenciu <nbianca@users.noreply.github.com>
33 lines
911 B
Ruby
33 lines
911 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::SendPushNotification do
|
|
fab!(:user) { Fabricate(:user) }
|
|
fab!(:subscription) { Fabricate(:push_subscription) }
|
|
let(:payload) { { notification_type: 1, excerpt: "Hello you" } }
|
|
|
|
before do
|
|
freeze_time
|
|
SiteSetting.push_notification_time_window_mins = 10
|
|
end
|
|
|
|
context "with active online user" do
|
|
it "does not send push notification" do
|
|
user.update!(last_seen_at: 5.minutes.ago)
|
|
|
|
PushNotificationPusher.expects(:push).with(user, payload).never
|
|
|
|
Jobs::SendPushNotification.new.execute(user_id: user, payload: payload)
|
|
end
|
|
end
|
|
|
|
context "with inactive offline user" do
|
|
it "sends push notification" do
|
|
user.update!(last_seen_at: 40.minutes.ago)
|
|
|
|
PushNotificationPusher.expects(:push).with(user, payload)
|
|
|
|
Jobs::SendPushNotification.new.execute(user_id: user, payload: payload)
|
|
end
|
|
end
|
|
end
|