Skip to content

Commit

Permalink
fix: correct IsImminent logic and improve notification template forma…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
revelaction committed Oct 3, 2024
1 parent ad415e7 commit 276f5d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 4 additions & 2 deletions ical/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import (
"time"
)

// LooseCategory is the category used to indicate that the event is without a fixed date or deadline
// LooseCategory is the category used to indicate that the event is without a
// fixed date or deadline
const LooseCategory = "loose"
// ShowAlarmCategory is the category used to indicate that the alarm details should be displayed in the notification
// ShowAlarmCategory is the category used to indicate that the alarm details
// should be displayed in the notification
const ShowAlarmCategory = "show-alarm"

type Parser struct {
Expand Down
15 changes: 6 additions & 9 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
)

const Tpl = `
{{- if and (not .Loose) .IsImminent}}
📢🔥🚨 IN {{.TimeDifference}} 🚨🔥📢
{{- end}}
{{- if .Summary}}
<b>{{.Summary}}</b>
<b> </b>
Expand Down Expand Up @@ -45,16 +48,10 @@ Attendees:
{{- end}}
{{- if .ShowAlarm}}
{{.Source}} 🔔 {{.DurIso8601}}
{{- end}}
{{- if and (not .Loose) .IsImminent}}
📢🔥🚨 IN {{.TimeDifference}} 🚨🔥📢
{{- end}}
`

const ImminenceThreshold = 1 * time.Hour
const ImminenceThreshold = 2 * time.Hour

type Notifier interface {
Notify(n Notification) error
Expand Down Expand Up @@ -122,9 +119,9 @@ func (n Notification) EventTimeTz() string {
return n.EventTime.Location().String()
}

// IsUrgent checks if the notification is urgent based on the difference between EventTime and Time
// IsImminent checks if the notification is urgent based on the difference between EventTime and Time
func (n Notification) IsImminent() bool {
return n.EventTime.Sub(n.Time) > ImminenceThreshold
return n.EventTime.Sub(n.Time) < ImminenceThreshold
}

// TimeDifference returns the difference between EventTime and Time
Expand Down

0 comments on commit 276f5d5

Please sign in to comment.