diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b4046df..9467f84a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fix bug in the "You're Going Oncall" push notification copy by @joeyorlando ([#1922](https://github.com/grafana/oncall/pull/1922)) + ## v1.2.21 (2023-05-09) ### Added diff --git a/engine/apps/mobile_app/tasks.py b/engine/apps/mobile_app/tasks.py index 841f7dde..5f300db2 100644 --- a/engine/apps/mobile_app/tasks.py +++ b/engine/apps/mobile_app/tasks.py @@ -314,6 +314,9 @@ def should_we_send_going_oncall_push_notification( Currently we will send notifications for the following scenarios: - schedule is starting in user's "configured notification timing preference" +/- a 4 minute buffer - schedule is starting within the next fifteen minutes + + Returns `None` if conditions are not met for the user to receive a push notification. Otherwise returns + an `int` which represents the # of seconds until the oncall shift starts. """ NOTIFICATION_TIMING_BUFFER = 7 * 60 # 7 minutes in seconds FIFTEEN_MINUTES_IN_SECONDS = 15 * 60 @@ -417,13 +420,13 @@ def conditionally_send_going_oncall_push_notifications_for_schedule(schedule_pk) cache_key = _generate_going_oncall_push_notification_cache_key(user_pk, schedule_event) already_sent_this_push_notification = cache_key in relevant_notifications_already_sent + seconds_until_going_oncall = should_we_send_going_oncall_push_notification( + now, mobile_app_user_settings, schedule_event + ) - if ( - should_we_send_going_oncall_push_notification(now, mobile_app_user_settings, schedule_event) - and not already_sent_this_push_notification - ): + if seconds_until_going_oncall is not None and not already_sent_this_push_notification: message = _get_youre_going_oncall_fcm_message( - user, schedule, device_to_notify, mobile_app_user_settings.going_oncall_notification_timing + user, schedule, device_to_notify, seconds_until_going_oncall ) _send_push_notification(device_to_notify, message) cache.set(cache_key, True, PUSH_NOTIFICATION_TRACKING_CACHE_KEY_TTL) diff --git a/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py b/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py index 76b77b7b..fde76af7 100644 --- a/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py +++ b/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py @@ -217,8 +217,9 @@ def test_conditionally_send_going_oncall_push_notifications_for_schedule( ), ] + seconds_until_shift_starts = 58989 mock_get_youre_going_oncall_fcm_message.return_value = mock_fcm_message - mock_should_we_send_going_oncall_push_notification.return_value = True + mock_should_we_send_going_oncall_push_notification.return_value = seconds_until_shift_starts mock_oncall_schedule_final_events.return_value = final_events schedule = make_schedule(organization, schedule_class=OnCallScheduleWeb) @@ -236,7 +237,7 @@ def test_conditionally_send_going_oncall_push_notifications_for_schedule( tasks.conditionally_send_going_oncall_push_notifications_for_schedule(schedule.pk) - mock_get_youre_going_oncall_fcm_message.assert_called_once_with(user, schedule, device, ONCALL_TIMING_PREFERENCE) + mock_get_youre_going_oncall_fcm_message.assert_called_once_with(user, schedule, device, seconds_until_shift_starts) mock_send_push_notification.assert_called_once_with(device, mock_fcm_message) assert cache.get(cache_key) is True