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

change youre going oncall push notification text to include the shift start/end #2123

Closed
Closed
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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

## Changed

- Update notification text for "You're going on call" push notifications to include information about the shift start
and end times by @joeyorlando ([#2123](https://github.com/grafana/oncall/pull/2123))

## v1.2.40 (2023-06-07)

### Added
Expand Down
38 changes: 34 additions & 4 deletions engine/apps/mobile_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from celery.utils.log import get_task_logger
from django.conf import settings
from django.core.cache import cache
from django.utils import timezone
from django.utils import dateformat, timezone
from fcm_django.models import FCMDevice
from firebase_admin.exceptions import FirebaseError
from firebase_admin.messaging import AndroidConfig, APNSConfig, APNSPayload, Aps, ApsAlert, CriticalSound, Message
Expand Down Expand Up @@ -224,8 +224,38 @@ def _get_alert_group_escalation_fcm_message(
return _construct_fcm_message(message_type, device_to_notify, thread_id, fcm_message_data, apns_payload)


def _get_youre_going_oncall_notification_title(
schedule: OnCallSchedule, seconds_until_going_oncall: int, schedule_event: ScheduleEvent
) -> str:
time_until_going_oncall = humanize.naturaldelta(seconds_until_going_oncall)

shift_start = schedule_event["start"]
shift_end = schedule_event["end"]
shift_starts_and_ends_on_same_day = shift_start.date() == shift_end.date()

def _format_datetime(dt):
"""
django's DateFormat class supports PHP date() style date formatting.
For example:
7th October 2003 11:39 (note the "th" part in "7th" isn't possible w/ Python datetime formatting)

https://stackoverflow.com/questions/3644417/python-format-datetime-with-st-nd-rd-th-english-ordinal-suffix-like
https://github.com/django/django/blob/main/django/utils/dateformat.py#L1-L12
"""
df = dateformat.DateFormat(dt)
return df.format("H:i" if shift_starts_and_ends_on_same_day else "F jS H:i")

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

return f"You're going on call in {time_until_going_oncall} for schedule {schedule.name}, {formatted_shift}"


def _get_youre_going_oncall_fcm_message(
user: User, schedule: OnCallSchedule, device_to_notify: FCMDevice, seconds_until_going_oncall: int
user: User,
schedule: OnCallSchedule,
device_to_notify: FCMDevice,
seconds_until_going_oncall: int,
schedule_event: ScheduleEvent,
) -> Message:
# avoid circular import
from apps.mobile_app.models import MobileAppUserSettings
Expand All @@ -234,8 +264,8 @@ def _get_youre_going_oncall_fcm_message(

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

notification_title = (
f"You are going on call in {humanize.naturaldelta(seconds_until_going_oncall)} for schedule {schedule.name}"
notification_title = _get_youre_going_oncall_notification_title(
schedule, seconds_until_going_oncall, schedule_event
)

data: FCMMessageData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def test_shift_starts_within_range(timing_window_lower, timing_window_upper, sec
)


def test_get_youre_going_oncall_notification_title():
# TODO:
pass


def test_get_youre_going_oncall_fcm_message():
# TODO:
pass


@pytest.mark.parametrize(
"info_notifications_enabled,now,going_oncall_notification_timing,schedule_start,expected",
[
Expand Down