feat(caldav): Sync Reminders / VALARM #1415

Merged
konrad merged 30 commits from ce72/api:1408_caldav_alarms into main 2023-04-01 11:09:13 +00:00
2 changed files with 18 additions and 13 deletions
Showing only changes of commit 4018bd6078 - Show all commits

View File

@ -143,8 +143,7 @@ func ParseTaskFromVTODO(content string) (vTask *models.Task, err error) {
reminders := make([]*models.TaskReminder, 0)
for _, vAlarm := range vTodo.SubComponents() {
switch vAlarm := vAlarm.(type) {
case *ics.VAlarm:
if vAlarm, ok := vAlarm.(*ics.VAlarm); ok {
reminders = parseVAlarm(vAlarm, reminders)
}
}
@ -158,14 +157,14 @@ func ParseTaskFromVTODO(content string) (vTask *models.Task, err error) {
func parseVAlarm(vAlarm *ics.VAlarm, reminders []*models.TaskReminder) []*models.TaskReminder {
for _, property := range vAlarm.UnknownPropertiesIANAProperties() {
if property.IANAToken == "TRIGGER" {
if len(property.ICalParameters["VALUE"]) > 0 {
switch property.ICalParameters["VALUE"][0] {
case "DATE-TIME":
switch {
case len(property.ICalParameters["VALUE"]) > 0:
if property.ICalParameters["VALUE"][0] == "DATE-TIME" {
// Example: TRIGGER;VALUE=DATE-TIME:20181201T011210Z
reminders = append(reminders, &models.TaskReminder{
Reminder: caldavTimeToTimestamp(property.Value)})
}
} else if len(property.ICalParameters["RELATED"]) > 0 {
case len(property.ICalParameters["RELATED"]) > 0:
duration := parseDuration(property.Value)
switch property.ICalParameters["RELATED"][0] {

Doesn't calDAV have a concept of a due date? And if that's the case, can't we use that as a relative anchor point?

Doesn't calDAV have a concept of a due date? And if that's the case, can't we use that as a relative anchor point?
Outdated
Review

I modified the implementation to follow more closely the CalDav standard
https://icalendar.org/iCalendar-RFC-5545/3-8-6-3-trigger.html

I also took a look at tasks.org CalDav implementation https://github.com/tasks/tasks/blob/main/app/src/main/java/org/tasks/caldav/extensions/VAlarm.kt

Can you please look at it again?

I modified the implementation to follow more closely the CalDav standard https://icalendar.org/iCalendar-RFC-5545/3-8-6-3-trigger.html I also took a look at tasks.org CalDav implementation https://github.com/tasks/tasks/blob/main/app/src/main/java/org/tasks/caldav/extensions/VAlarm.kt Can you please look at it again?

I think this is fine now.

I think this is fine now.
case "START":
@ -179,14 +178,12 @@ func parseVAlarm(vAlarm *ics.VAlarm, reminders []*models.TaskReminder) []*models
RelativePeriod: int64(duration.Seconds()),
RelativeTo: models.ReminderRelationEndDate})
}
} else {
default:
duration := parseDuration(property.Value)
if duration != 0 {
// Example: TRIGGER:-PT60M
reminders = append(reminders, &models.TaskReminder{
RelativePeriod: int64(duration.Seconds()),
RelativeTo: models.ReminderRelationDueDate})
}
// Example: TRIGGER:-PT60M
reminders = append(reminders, &models.TaskReminder{
RelativePeriod: int64(duration.Seconds()),
RelativeTo: models.ReminderRelationDueDate})
}
}
}

View File

@ -166,6 +166,10 @@ DESCRIPTION:Lorem Ipsum
DTSTART:20230228T170000Z
DUE:20230304T150000Z
BEGIN:VALARM
TRIGGER:PT0S
ACTION:DISPLAY
END:VALARM
BEGIN:VALARM
TRIGGER:-PT60M
ACTION:DISPLAY
END:VALARM
@ -187,6 +191,10 @@ END:VCALENDAR`,
StartDate: time.Date(2023, 2, 28, 17, 0, 0, 0, config.GetTimeZone()),
DueDate: time.Date(2023, 3, 4, 15, 0, 0, 0, config.GetTimeZone()),
Reminders: []*models.TaskReminder{
{
RelativeTo: models.ReminderRelationDueDate,
RelativePeriod: 0,
},
{
RelativeTo: models.ReminderRelationDueDate,
RelativePeriod: -3600,