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

changed notification title and subtitle; removed body #2027

Merged
merged 13 commits into from
May 26, 2023
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. by @imtoori [#2027](https://github.com/grafana/oncall/pull/2027)

## v1.2.30 (2023-05-25)

### Fixed
Expand Down
27 changes: 23 additions & 4 deletions engine/apps/mobile_app/alert_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,30 @@ 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()

number_of_alerts = alert_group.alerts.count()
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"
+ f"via {alert_group.channel.short_name}"
+ f"\n{alert_status}"
)

return emojize(subtitle, use_aliases=True)
25 changes: 5 additions & 20 deletions engine/apps/mobile_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -153,24 +153,9 @@ 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 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 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)

Expand All @@ -189,7 +174,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,
Expand Down Expand Up @@ -217,11 +201,12 @@ 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,
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,
Expand Down