Skip to content

Commit 0177301

Browse files
imtoorijoeyorlando
andauthored
refactor title and subtitle of shift notifications (#2288)
# What this PR does ## Which issue(s) this PR fixes ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --------- Co-authored-by: Joey Orlando <[email protected]> Co-authored-by: Joey Orlando <[email protected]>
1 parent 4f2d3be commit 0177301

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
## Changed
11+
12+
- Change mobile shift notifications title and subtitle by @imtoori ([#2288](https://github.com/grafana/oncall/pull/2288))
13+
814
## v1.2.45 (2023-06-19)
915

1016
### Changed

engine/apps/mobile_app/tasks.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,17 @@ def _get_alert_group_escalation_fcm_message(
226226
return _construct_fcm_message(message_type, device_to_notify, thread_id, fcm_message_data, apns_payload)
227227

228228

229-
def _get_youre_going_oncall_notification_title(
229+
def _get_youre_going_oncall_notification_title(seconds_until_going_oncall: int) -> str:
230+
time_until_going_oncall = humanize.naturaldelta(seconds_until_going_oncall)
231+
232+
return f"Your on-call shift starts in {time_until_going_oncall}"
233+
234+
235+
def _get_youre_going_oncall_notification_subtitle(
230236
schedule: OnCallSchedule,
231-
seconds_until_going_oncall: int,
232237
schedule_event: ScheduleEvent,
233238
mobile_app_user_settings: "MobileAppUserSettings",
234239
) -> str:
235-
time_until_going_oncall = humanize.naturaldelta(seconds_until_going_oncall)
236-
237240
shift_start = schedule_event["start"]
238241
shift_end = schedule_event["end"]
239242
shift_starts_and_ends_on_same_day = shift_start.date() == shift_end.date()
@@ -244,7 +247,7 @@ def _format_datetime(dt):
244247

245248
formatted_shift = f"{_format_datetime(shift_start)} - {_format_datetime(shift_end)}"
246249

247-
return f"You're going on call in {time_until_going_oncall} for schedule {schedule.name}, {formatted_shift}"
250+
return f"{formatted_shift}\nSchedule {schedule.name}"
248251

249252

250253
def _get_youre_going_oncall_fcm_message(
@@ -261,12 +264,14 @@ def _get_youre_going_oncall_fcm_message(
261264

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

264-
notification_title = _get_youre_going_oncall_notification_title(
265-
schedule, seconds_until_going_oncall, schedule_event, mobile_app_user_settings
267+
notification_title = _get_youre_going_oncall_notification_title(seconds_until_going_oncall)
268+
notification_subtitle = _get_youre_going_oncall_notification_subtitle(
269+
schedule, schedule_event, mobile_app_user_settings
266270
)
267271

268272
data: FCMMessageData = {
269273
"title": notification_title,
274+
"subtitle": notification_subtitle,
270275
"info_notification_sound_name": (
271276
mobile_app_user_settings.info_notification_sound_name + MobileAppUserSettings.ANDROID_SOUND_NAME_EXTENSION
272277
),
@@ -278,7 +283,7 @@ def _get_youre_going_oncall_fcm_message(
278283
apns_payload = APNSPayload(
279284
aps=Aps(
280285
thread_id=thread_id,
281-
alert=ApsAlert(title=notification_title),
286+
alert=ApsAlert(title=notification_title, subtitle=notification_subtitle),
282287
sound=CriticalSound(
283288
critical=False,
284289
name=mobile_app_user_settings.info_notification_sound_name

engine/apps/mobile_app/tests/test_your_going_oncall_notification.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -95,42 +95,36 @@ def test_get_youre_going_oncall_notification_title(make_organization_and_user, m
9595
##################
9696
# same day shift
9797
##################
98-
same_day_shift_title = tasks._get_youre_going_oncall_notification_title(
99-
schedule, seconds_until_going_oncall, same_day_shift, maus
100-
)
101-
same_day_shift_no_locale_title = tasks._get_youre_going_oncall_notification_title(
102-
schedule, seconds_until_going_oncall, same_day_shift, maus_no_locale
98+
same_day_shift_title = tasks._get_youre_going_oncall_notification_title(seconds_until_going_oncall)
99+
same_day_shift_subtitle = tasks._get_youre_going_oncall_notification_subtitle(schedule, same_day_shift, maus)
100+
same_day_shift_no_locale_subtitle = tasks._get_youre_going_oncall_notification_subtitle(
101+
schedule, same_day_shift, maus_no_locale
103102
)
104103

105-
assert (
106-
same_day_shift_title
107-
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 09 h 00 - 17 h 00"
108-
)
109-
assert (
110-
same_day_shift_no_locale_title
111-
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 9:00\u202fAM - 5:00\u202fPM"
112-
)
104+
assert same_day_shift_title == f"Your on-call shift starts in {humanized_time_until_going_oncall}"
105+
assert same_day_shift_subtitle == f"09 h 00 - 17 h 00\nSchedule {schedule_name}"
106+
assert same_day_shift_no_locale_subtitle == f"9:00\u202fAM - 5:00\u202fPM\nSchedule {schedule_name}"
113107

114108
##################
115109
# multiple day shift
116110
##################
117-
multiple_day_shift_title = tasks._get_youre_going_oncall_notification_title(
118-
schedule, seconds_until_going_oncall, multiple_day_shift, maus
111+
multiple_day_shift_title = tasks._get_youre_going_oncall_notification_title(seconds_until_going_oncall)
112+
multiple_day_shift_subtitle = tasks._get_youre_going_oncall_notification_subtitle(
113+
schedule, multiple_day_shift, maus
119114
)
120-
multiple_day_shift_no_locale_title = tasks._get_youre_going_oncall_notification_title(
121-
schedule, seconds_until_going_oncall, multiple_day_shift, maus_no_locale
115+
multiple_day_shift_no_locale_subtitle = tasks._get_youre_going_oncall_notification_subtitle(
116+
schedule, multiple_day_shift, maus_no_locale
122117
)
123118

119+
assert multiple_day_shift_title == f"Your on-call shift starts in {humanized_time_until_going_oncall}"
120+
assert multiple_day_shift_subtitle == f"2023-07-08 09 h 00 - 2023-07-12 17 h 00\nSchedule {schedule_name}"
124121
assert (
125-
multiple_day_shift_title
126-
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 2023-07-08 09 h 00 - 2023-07-12 17 h 00"
127-
)
128-
assert (
129-
multiple_day_shift_no_locale_title
130-
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 7/8/23, 9:00\u202fAM - 7/12/23, 5:00\u202fPM"
122+
multiple_day_shift_no_locale_subtitle
123+
== f"7/8/23, 9:00\u202fAM - 7/12/23, 5:00\u202fPM\nSchedule {schedule_name}"
131124
)
132125

133126

127+
@mock.patch("apps.mobile_app.tasks._get_youre_going_oncall_notification_subtitle")
134128
@mock.patch("apps.mobile_app.tasks._get_youre_going_oncall_notification_title")
135129
@mock.patch("apps.mobile_app.tasks._construct_fcm_message")
136130
@mock.patch("apps.mobile_app.tasks.APNSPayload")
@@ -145,16 +139,19 @@ def test_get_youre_going_oncall_fcm_message(
145139
mock_apns_payload,
146140
mock_construct_fcm_message,
147141
mock_get_youre_going_oncall_notification_title,
142+
mock_get_youre_going_oncall_notification_subtitle,
148143
make_organization_and_user,
149144
make_schedule,
150145
):
151146
mock_fcm_message = "mncvmnvcmnvcnmvcmncvmn"
152147
mock_notification_title = "asdfasdf"
148+
mock_notification_subtitle = f"9:06\u202fAM - 9:06\u202fAM\nSchedule XYZ"
153149
shift_pk = "mncvmnvc"
154150
seconds_until_going_oncall = 600
155151

156152
mock_construct_fcm_message.return_value = mock_fcm_message
157153
mock_get_youre_going_oncall_notification_title.return_value = mock_notification_title
154+
mock_get_youre_going_oncall_notification_subtitle.return_value = mock_notification_subtitle
158155

159156
organization, user = make_organization_and_user()
160157
user_pk = user.public_primary_key
@@ -177,6 +174,7 @@ def test_get_youre_going_oncall_fcm_message(
177174

178175
data = {
179176
"title": mock_notification_title,
177+
"subtitle": mock_notification_subtitle,
180178
"info_notification_sound_name": (
181179
maus.info_notification_sound_name + MobileAppUserSettings.ANDROID_SOUND_NAME_EXTENSION
182180
),
@@ -191,7 +189,7 @@ def test_get_youre_going_oncall_fcm_message(
191189

192190
assert fcm_message == mock_fcm_message
193191

194-
mock_aps_alert.assert_called_once_with(title=mock_notification_title)
192+
mock_aps_alert.assert_called_once_with(title=mock_notification_title, subtitle=mock_notification_subtitle)
195193
mock_critical_sound.assert_called_once_with(
196194
critical=False, name=maus.info_notification_sound_name + MobileAppUserSettings.IOS_SOUND_NAME_EXTENSION
197195
)
@@ -205,9 +203,9 @@ def test_get_youre_going_oncall_fcm_message(
205203
)
206204
mock_apns_payload.assert_called_once_with(aps=mock_aps.return_value)
207205

208-
mock_get_youre_going_oncall_notification_title.assert_called_once_with(
209-
schedule, seconds_until_going_oncall, schedule_event, maus
210-
)
206+
mock_get_youre_going_oncall_notification_subtitle.assert_called_once_with(schedule, schedule_event, maus)
207+
mock_get_youre_going_oncall_notification_title.assert_called_once_with(seconds_until_going_oncall)
208+
211209
mock_construct_fcm_message.assert_called_once_with(
212210
tasks.MessageType.INFO, device, notification_thread_id, data, mock_apns_payload.return_value
213211
)

0 commit comments

Comments
 (0)