Fixed the way cancellation is determined (fixes #3)

This commit is contained in:
Andreas Schneider 2018-04-06 09:32:34 +02:00
parent fd0f4bf3c3
commit 3f84913b74
2 changed files with 15 additions and 3 deletions

View File

@ -25,7 +25,7 @@ func main() {
for _, item := range items { for _, item := range items {
// Ignore private items. // Ignore private items.
if item.Sensitivity != "Private" && !item.IsCancelled { if item.Sensitivity != "Private" && !item.IsCancelled() {
// None-private items though ... remember them by hash. // None-private items though ... remember them by hash.
// The hash will equal the CalDAV UID (and its filename). // The hash will equal the CalDAV UID (and its filename).
relevantEWSItems[item.Hash()] = item relevantEWSItems[item.Hash()] = item

View File

@ -29,10 +29,18 @@ type CalendarItem struct {
RecurrenceId string RecurrenceId string
Sensitivity string Sensitivity string
CalendarItemType string CalendarItemType string
IsCancelled bool AppointmentState AppointmentState
IsAllDayEvent bool IsAllDayEvent bool
} }
type AppointmentState int
const (
AppointmentStateMeeting AppointmentState = 1 << iota // This appointment is a meeting.
AppointmentStateReceived // This appointment has been received.
AppointmentStateCancelled // This appointment has been canceled.
)
// Build a hash for the given calendar item by combining the UID and // Build a hash for the given calendar item by combining the UID and
// the recurrenceId therefore guaranteeing a unique identifier for the // the recurrenceId therefore guaranteeing a unique identifier for the
// event, even if it has been a calculated recurrence (which would // event, even if it has been a calculated recurrence (which would
@ -44,6 +52,10 @@ func (ci CalendarItem) Hash() string {
return strings.ToUpper(hex.EncodeToString(h.Sum(nil))) return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
} }
func (ci CalendarItem) IsCancelled() bool {
return ci.AppointmentState&AppointmentStateCancelled != 0
}
type EWSCalendar struct { type EWSCalendar struct {
httpClient *http.Client httpClient *http.Client
url string url string
@ -262,7 +274,7 @@ var calendarQuery = template.Must(template.New("calendarQuery").Parse(`<?xml ver
<t:FieldURI FieldURI="calendar:End" /> <t:FieldURI FieldURI="calendar:End" />
<t:FieldURI FieldURI="calendar:UID" /> <t:FieldURI FieldURI="calendar:UID" />
<t:FieldURI FieldURI="calendar:RecurrenceId" /> <t:FieldURI FieldURI="calendar:RecurrenceId" />
<t:FieldURI FieldURI="calendar:IsCancelled" /> <t:FieldURI FieldURI="calendar:AppointmentState" />
<t:FieldURI FieldURI="calendar:CalendarItemType" /> <t:FieldURI FieldURI="calendar:CalendarItemType" />
<t:FieldURI FieldURI="calendar:IsAllDayEvent" /> <t:FieldURI FieldURI="calendar:IsAllDayEvent" />
</t:AdditionalProperties> </t:AdditionalProperties>