From b52a4ed2bac528d233ebb5b0033760dad303b466 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 May 2023 17:33:14 +0200 Subject: [PATCH 01/12] changed notification title and subtitle; removed body --- engine/apps/mobile_app/alert_rendering.py | 27 ++++++++++++++++++----- engine/apps/mobile_app/tasks.py | 23 ++++--------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index 0aee03f517..0acb72ef17 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -9,11 +9,28 @@ def _render_for(self): return "MOBILE_APP" -def get_push_notification_message(alert_group): +def get_push_notification_subtitle(alert_group): alert = alert_group.alerts.first() templated_alert = AlertMobileAppTemplater(alert).render() - title = str_or_backup(templated_alert.title, "Alert Group") + alert_title = str_or_backup(templated_alert.title, "Alert Group") - return emojize( - f"#{alert_group.inside_organization_number} {title} via {alert_group.channel.short_name}", use_aliases=True - ) + status_verbose = "Firing" # TODO: we should probably de-duplicate this text + if alert_group.resolved: + status_verbose = alert_group.get_resolve_text() + elif alert_group.acknowledged: + status_verbose = alert_group.get_acknowledge_text() + + if number_of_alerts <= 10: + alerts_count_str = str(number_of_alerts) + else: + alert_count_rounded = (number_of_alerts // 10) * 10 + alerts_count_str = f"{alert_count_rounded}+" + + alert_status = f"Status: {status_verbose}, alerts: {alerts_count_str}" + + + subtitle = f"#{alert_group.inside_organization_number} {alert_title}\n" + + emojize(f"{title} via {alert_group.channel.short_name}", use_aliases=True) + + f"\n{alert_status}" + + return subtitle diff --git a/engine/apps/mobile_app/tasks.py b/engine/apps/mobile_app/tasks.py index 10677e2e88..7f43d849a5 100644 --- a/engine/apps/mobile_app/tasks.py +++ b/engine/apps/mobile_app/tasks.py @@ -18,7 +18,7 @@ from apps.alerts.models import AlertGroup from apps.base.utils import live_settings -from apps.mobile_app.alert_rendering import get_push_notification_message +from apps.mobile_app.alert_rendering import get_push_notification_subtitle from apps.schedules.models.on_call_schedule import OnCallSchedule, ScheduleEvent from apps.user_management.models import User from common.api_helpers.utils import create_engine_url @@ -155,22 +155,8 @@ def _get_alert_group_escalation_fcm_message( thread_id = f"{alert_group.channel.organization.public_primary_key}:{alert_group.public_primary_key}" number_of_alerts = alert_group.alerts.count() - alert_title = "New Critical Alert" if critical else "New Alert" - alert_subtitle = get_push_notification_message(alert_group) - - status_verbose = "Firing" # TODO: we should probably de-duplicate this text - if alert_group.resolved: - status_verbose = alert_group.get_resolve_text() - elif alert_group.acknowledged: - status_verbose = alert_group.get_acknowledge_text() - - if number_of_alerts <= 10: - alerts_count_str = str(number_of_alerts) - else: - alert_count_rounded = (number_of_alerts // 10) * 10 - alerts_count_str = f"{alert_count_rounded}+" - - alert_body = f"Status: {status_verbose}, alerts: {alerts_count_str}" + alert_title = "New Alert" if critical else "New Important Alert" + alert_subtitle = get_push_notification_subtitle(alert_group) mobile_app_user_settings, _ = MobileAppUserSettings.objects.get_or_create(user=user) @@ -189,7 +175,6 @@ def _get_alert_group_escalation_fcm_message( fcm_message_data: FCMMessageData = { "title": alert_title, "subtitle": alert_subtitle, - "body": alert_body, "orgId": alert_group.channel.organization.public_primary_key, "orgName": alert_group.channel.organization.stack_slug, "alertGroupId": alert_group.public_primary_key, @@ -221,7 +206,7 @@ def _get_alert_group_escalation_fcm_message( aps=Aps( thread_id=thread_id, badge=number_of_alerts, - alert=ApsAlert(title=alert_title, subtitle=alert_subtitle, body=alert_body), + alert=ApsAlert(title=alert_title, subtitle=alert_subtitle), sound=CriticalSound( # The notification shouldn't be critical if the user has disabled "override DND" setting critical=overrideDND, From a8e8baf742ea5119017dc3789389107203f07839 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 May 2023 17:58:56 +0200 Subject: [PATCH 02/12] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a5bd889c6..8273864ad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ the destination country code by @mderynck ([#1976](https://github.com/grafana/on - Fix error when updating closed modal window in Slack by @vadimkerr ([#2019](https://github.com/grafana/oncall/pull/2019)) - Fix final schedule export failing to update when ical imported events set start/end as date ([#2025](https://github.com/grafana/oncall/pull/2025)) +### Changed + +- Changed mobile notification title and subtitle. Removed the body. [#2027](https://github.com/grafana/oncall/pull/2027) + ## v1.2.30 (2023-05-25) ### Fixed From 6f4b9b747e68cc7eda1d56dfa03d6cd53afbb0ce Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 May 2023 18:04:22 +0200 Subject: [PATCH 03/12] fix title --- engine/apps/mobile_app/alert_rendering.py | 3 ++- engine/apps/mobile_app/tasks.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index 0acb72ef17..1cfd169d3c 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -20,6 +20,7 @@ def get_push_notification_subtitle(alert_group): elif alert_group.acknowledged: status_verbose = alert_group.get_acknowledge_text() + number_of_alerts = alert_group.alerts.count() if number_of_alerts <= 10: alerts_count_str = str(number_of_alerts) else: @@ -30,7 +31,7 @@ def get_push_notification_subtitle(alert_group): subtitle = f"#{alert_group.inside_organization_number} {alert_title}\n" - + emojize(f"{title} via {alert_group.channel.short_name}", use_aliases=True) + + emojize(f"via {alert_group.channel.short_name}", use_aliases=True) + f"\n{alert_status}" return subtitle diff --git a/engine/apps/mobile_app/tasks.py b/engine/apps/mobile_app/tasks.py index 7f43d849a5..3fccca128e 100644 --- a/engine/apps/mobile_app/tasks.py +++ b/engine/apps/mobile_app/tasks.py @@ -153,7 +153,6 @@ def _get_alert_group_escalation_fcm_message( from apps.mobile_app.models import MobileAppUserSettings thread_id = f"{alert_group.channel.organization.public_primary_key}:{alert_group.public_primary_key}" - number_of_alerts = alert_group.alerts.count() alert_title = "New Alert" if critical else "New Important Alert" alert_subtitle = get_push_notification_subtitle(alert_group) From 571a6dd2f53da36a99e37350b3fbcf11a279d00c Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 May 2023 18:11:37 +0200 Subject: [PATCH 04/12] fix lint --- engine/apps/mobile_app/alert_rendering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index 1cfd169d3c..6d160c8735 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -31,7 +31,7 @@ def get_push_notification_subtitle(alert_group): subtitle = f"#{alert_group.inside_organization_number} {alert_title}\n" - + emojize(f"via {alert_group.channel.short_name}", use_aliases=True) - + f"\n{alert_status}" + +emojize(f"via {alert_group.channel.short_name}", use_aliases=True) + +f"\n{alert_status}" return subtitle From 2780bba3435c460186ebe026546891bfbe8ef609 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 May 2023 18:17:00 +0200 Subject: [PATCH 05/12] fix lint --- engine/apps/mobile_app/alert_rendering.py | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index 6d160c8735..eef73e979d 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -29,7 +29,6 @@ def get_push_notification_subtitle(alert_group): alert_status = f"Status: {status_verbose}, alerts: {alerts_count_str}" - subtitle = f"#{alert_group.inside_organization_number} {alert_title}\n" +emojize(f"via {alert_group.channel.short_name}", use_aliases=True) +f"\n{alert_status}" From f19a40afbd64d9c30f50779f0729a7b109f45a63 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 May 2023 18:22:10 +0200 Subject: [PATCH 06/12] fix lint --- engine/apps/mobile_app/alert_rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index eef73e979d..685acb1cc0 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -29,7 +29,7 @@ def get_push_notification_subtitle(alert_group): alert_status = f"Status: {status_verbose}, alerts: {alerts_count_str}" - subtitle = f"#{alert_group.inside_organization_number} {alert_title}\n" + subtitle = f"#{alert_group.inside_organization_number} {alert_title}\n" +emojize(f"via {alert_group.channel.short_name}", use_aliases=True) +f"\n{alert_status}" From 0f65a18de4715b036fd0b4718ec5df65e9f44fc4 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 May 2023 09:37:02 +0200 Subject: [PATCH 07/12] fix alert title --- engine/apps/mobile_app/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/apps/mobile_app/tasks.py b/engine/apps/mobile_app/tasks.py index 3fccca128e..9927936c7d 100644 --- a/engine/apps/mobile_app/tasks.py +++ b/engine/apps/mobile_app/tasks.py @@ -154,7 +154,7 @@ def _get_alert_group_escalation_fcm_message( thread_id = f"{alert_group.channel.organization.public_primary_key}:{alert_group.public_primary_key}" - alert_title = "New Alert" if critical else "New Important Alert" + alert_title = "New Important Alert" if critical else "New Alert" alert_subtitle = get_push_notification_subtitle(alert_group) mobile_app_user_settings, _ = MobileAppUserSettings.objects.get_or_create(user=user) From e4cc45d0b9e8c67504d1004ae546cac996d9582d Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 May 2023 09:38:36 +0200 Subject: [PATCH 08/12] fix string construction --- engine/apps/mobile_app/alert_rendering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index 685acb1cc0..b346a992eb 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -29,8 +29,8 @@ def get_push_notification_subtitle(alert_group): alert_status = f"Status: {status_verbose}, alerts: {alerts_count_str}" - subtitle = f"#{alert_group.inside_organization_number} {alert_title}\n" + subtitle = (f"#{alert_group.inside_organization_number} {alert_title}\n" +emojize(f"via {alert_group.channel.short_name}", use_aliases=True) - +f"\n{alert_status}" + +f"\n{alert_status}") return subtitle From cb6524208928c2900474a12ade988bb51cb918aa Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 May 2023 09:44:02 +0200 Subject: [PATCH 09/12] fix lint --- engine/apps/mobile_app/alert_rendering.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index b346a992eb..fa5c1ceae5 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -29,8 +29,10 @@ def get_push_notification_subtitle(alert_group): alert_status = f"Status: {status_verbose}, alerts: {alerts_count_str}" - subtitle = (f"#{alert_group.inside_organization_number} {alert_title}\n" - +emojize(f"via {alert_group.channel.short_name}", use_aliases=True) - +f"\n{alert_status}") + subtitle = ( + f"#{alert_group.inside_organization_number} {alert_title}\n" + + emojize(f"via {alert_group.channel.short_name}", use_aliases=True) + + f"\n{alert_status}" + ) return subtitle From 3a33b45e173ac25ccbd515ed89255ca340607e95 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 May 2023 09:59:11 +0200 Subject: [PATCH 10/12] fix test --- engine/apps/mobile_app/tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/apps/mobile_app/tasks.py b/engine/apps/mobile_app/tasks.py index 9927936c7d..6c6afa5d4d 100644 --- a/engine/apps/mobile_app/tasks.py +++ b/engine/apps/mobile_app/tasks.py @@ -201,6 +201,7 @@ def _get_alert_group_escalation_fcm_message( "important_notification_override_dnd": json.dumps(mobile_app_user_settings.important_notification_override_dnd), } + number_of_alerts = alert_group.alerts.count() apns_payload = APNSPayload( aps=Aps( thread_id=thread_id, From 088ba31b61f841049ecad96d51f02c4fdb2a1489 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 May 2023 14:37:15 +0200 Subject: [PATCH 11/12] Update CHANGELOG.md Co-authored-by: Joey Orlando --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8273864ad3..b78cea9444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ the destination country code by @mderynck ([#1976](https://github.com/grafana/on ### Changed -- Changed mobile notification title and subtitle. Removed the body. [#2027](https://github.com/grafana/oncall/pull/2027) +- Changed mobile notification title and subtitle. Removed the body. by @imtoori [#2027](https://github.com/grafana/oncall/pull/2027) ## v1.2.30 (2023-05-25) From 29f31af4655eac6e0cc3ef9efb3a90c538613c92 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 May 2023 14:40:18 +0200 Subject: [PATCH 12/12] emojize all subtitle --- engine/apps/mobile_app/alert_rendering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/apps/mobile_app/alert_rendering.py b/engine/apps/mobile_app/alert_rendering.py index fa5c1ceae5..3b0c95389e 100644 --- a/engine/apps/mobile_app/alert_rendering.py +++ b/engine/apps/mobile_app/alert_rendering.py @@ -31,8 +31,8 @@ def get_push_notification_subtitle(alert_group): subtitle = ( f"#{alert_group.inside_organization_number} {alert_title}\n" - + emojize(f"via {alert_group.channel.short_name}", use_aliases=True) + + f"via {alert_group.channel.short_name}" + f"\n{alert_status}" ) - return subtitle + return emojize(subtitle, use_aliases=True)