Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update apns payload with corrected interruption-level field #1646

Merged
merged 6 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

- Addressed bug with iOS mobile push notifications always being set to critical by @imtoori and @joeyorlando ([#1646](https://github.com/grafana/oncall/pull/1646))
vstpme marked this conversation as resolved.
Show resolved Hide resolved

## v1.2.2 (2023-03-27)

### Changed
Expand Down
8 changes: 6 additions & 2 deletions engine/apps/mobile_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def _get_fcm_message(alert_group, user, registration_id, critical):

mobile_app_user_settings, _ = MobileAppUserSettings.objects.get_or_create(user=user)

# critical defines the type of notification.
# we use overrideDND to establish if the notification should sound even if DND is on
overrideDND = critical and mobile_app_user_settings.important_notification_override_dnd

# APNS only allows to specify volume for critical notifications
apns_volume = mobile_app_user_settings.important_notification_volume if critical else None
apns_sound_name = (
Expand Down Expand Up @@ -208,12 +212,12 @@ def _get_fcm_message(alert_group, user, registration_id, critical):
alert=ApsAlert(title=alert_title, subtitle=alert_subtitle, body=alert_body),
sound=CriticalSound(
# The notification shouldn't be critical if the user has disabled "override DND" setting
critical=(critical and mobile_app_user_settings.important_notification_override_dnd),
joeyorlando marked this conversation as resolved.
Show resolved Hide resolved
critical=overrideDND,
name=apns_sound_name,
volume=apns_volume,
),
custom_data={
"interruption-level": "critical" if critical else "time-sensitive",
"interruption-level": "critical" if overrideDND else "time-sensitive",
},
),
),
Expand Down
2 changes: 2 additions & 0 deletions engine/apps/mobile_app/tests/test_notify_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def test_fcm_message_user_settings_critical(
assert apns_sound.critical is True
assert apns_sound.name == "default_sound_important.aiff"
assert apns_sound.volume == 0.8
assert message.apns.payload.aps.custom_data["interruption-level"] == "critical"


@pytest.mark.django_db
Expand All @@ -293,3 +294,4 @@ def test_fcm_message_user_settings_critical_override_dnd_disabled(
# Check APNS notification sound is set correctly
apns_sound = message.apns.payload.aps.sound
assert apns_sound.critical is False
assert message.apns.payload.aps.custom_data["interruption-level"] == "time-sensitive"