Fix #2: ical calendar: take 'cancelled' status into account #4
@ -129,7 +129,22 @@ func (cal *RemoteCalendar) LoadNextMeetingTime(ctx context.Context) (time.Time,
|
||||
var nextStartTime time.Time
|
||||
|
||||
for eventIndex, event := range events {
|
||||
uid := event.GetProperty(ical.ComponentPropertyUniqueId)
|
||||
if uid == nil {
|
||||
log.Warn("calendar: ignoring entry without UID property")
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip cancelled meetings.
|
||||
if isCancelled(event) {
|
||||
continue
|
||||
}
|
||||
|
||||
dtStart := event.GetProperty(ical.ComponentPropertyDtStart)
|
||||
if dtStart == nil {
|
||||
log.Warn("calendar: ignoring entry without DTSTART property", "uid", uid.Value)
|
||||
continue
|
||||
}
|
||||
parsedDtStart, err := time.Parse(icalTimeFormat, dtStart.Value)
|
||||
if err != nil {
|
||||
log.Warn("calendar: could not parse DTSTART property", "value", dtStart.Value, "cause", err)
|
||||
@ -146,17 +161,22 @@ func (cal *RemoteCalendar) LoadNextMeetingTime(ctx context.Context) (time.Time,
|
||||
return nextStartTime, nil
|
||||
}
|
||||
|
||||
func (cal *RemoteCalendar) MeetingsOnMonth(ctx context.Context, timeInMonth time.Time) []time.Time {
|
||||
type MeetingInfo struct {
|
||||
StartTime time.Time
|
||||
IsCancelled bool
|
||||
}
|
||||
|
||||
func (cal *RemoteCalendar) MeetingsOnMonth(ctx context.Context, timeInMonth time.Time) []MeetingInfo {
|
||||
log := GetBotLog(ctx)
|
||||
|
||||
calendar, err := cal.LoadFromDisk(ctx)
|
||||
if err != nil {
|
||||
log.Warn("could not load calendar from disk, pretending there are no meetings", "cause", err)
|
||||
return []time.Time{}
|
||||
return []MeetingInfo{}
|
||||
}
|
||||
|
||||
events := calendar.Events()
|
||||
inMonth := []time.Time{}
|
||||
inMonth := []MeetingInfo{}
|
||||
|
||||
year := timeInMonth.Year()
|
||||
month := timeInMonth.Month()
|
||||
@ -173,7 +193,12 @@ func (cal *RemoteCalendar) MeetingsOnMonth(ctx context.Context, timeInMonth time
|
||||
if parsedDtStart.Year() != year || parsedDtStart.Month() != month {
|
||||
continue
|
||||
}
|
||||
inMonth = append(inMonth, parsedDtStart.In(location))
|
||||
|
||||
meetingInfo := MeetingInfo{
|
||||
StartTime: parsedDtStart.In(location),
|
||||
IsCancelled: isCancelled(event),
|
||||
}
|
||||
inMonth = append(inMonth, meetingInfo)
|
||||
}
|
||||
|
||||
return inMonth
|
||||
@ -294,3 +319,11 @@ func fileExists(path string) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func isCancelled(event *ical.VEvent) bool {
|
||||
status := event.GetProperty(ical.ComponentPropertyStatus)
|
||||
if status == nil {
|
||||
return false
|
||||
}
|
||||
return status.Value == string(ical.ObjectStatusCancelled)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user