Skip to content

Commit

Permalink
review comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joosakur committed Nov 22, 2024
1 parent f80084e commit 5db7d19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@ class CalendarEventController(
} +
groupDevices.map {
AsyncJob.SendCalendarEventReservationPushNotification(
user = user,
device = it.device,
groupId = it.groupId,
type =
Expand Down Expand Up @@ -887,7 +886,6 @@ class CalendarEventController(
} +
groupDevices.map {
AsyncJob.SendCalendarEventReservationPushNotification(
user = user,
device = it.device,
groupId = it.groupId,
type =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import fi.espoo.evaka.shared.async.AsyncJobRunner
import fi.espoo.evaka.shared.auth.AuthenticatedUser
import fi.espoo.evaka.shared.db.Database
import fi.espoo.evaka.shared.domain.EvakaClock
import fi.espoo.evaka.shared.domain.HelsinkiDateTime
import fi.espoo.evaka.shared.security.AccessControl
import fi.espoo.evaka.shared.security.Action
import fi.espoo.evaka.webpush.WebPush
Expand Down Expand Up @@ -84,6 +85,17 @@ AND 'CALENDAR_EVENT_RESERVATION' = ANY(md.push_notification_categories)
) {
if (webPush == null) return

val untilReservationEnd =
Duration.between(
clock.now().toInstant(),
HelsinkiDateTime.of(job.date, job.endTime).toInstant(),
)

if (untilReservationEnd.isNegative) {
// reservation is in the past, no need to send notification
return
}

val device = job.device

val (vapidJwt, notification) =
Expand Down Expand Up @@ -113,7 +125,7 @@ AND 'CALENDAR_EVENT_RESERVATION' = ANY(md.push_notification_categories)
vapidJwt,
WebPushNotification(
notification.endpoint,
ttl = Duration.ofDays(1),
ttl = untilReservationEnd.coerceIn(Duration.ofMinutes(15), Duration.ofDays(5)),
payloads =
listOf(
WebPushPayload.NotificationV1(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ sealed interface AsyncJob : AsyncJobPayload {
}

data class SendCalendarEventReservationPushNotification(
override val user: AuthenticatedUser,
val device: MobileDeviceId,
val groupId: GroupId,
val type: CalendarEventReservationNotificationType,
val date: LocalDate,
val startTime: LocalTime,
val endTime: LocalTime,
) : AsyncJob
) : AsyncJob {
override val user: AuthenticatedUser? = null
}

data class UploadToKoski(val key: KoskiStudyRightKey) : AsyncJob {
override val user: AuthenticatedUser? = null
Expand Down

0 comments on commit 5db7d19

Please sign in to comment.