diff --git a/pkg/caldav/caldav.go b/pkg/caldav/caldav.go index 228aa7a78..f2f34bab2 100644 --- a/pkg/caldav/caldav.go +++ b/pkg/caldav/caldav.go @@ -37,6 +37,7 @@ type Event struct { Description string UID string Alarms []Alarm + Color string Timestamp time.Time Start time.Time @@ -56,6 +57,7 @@ type Todo struct { Organizer *user.User Priority int64 // 0-9, 1 is highest RelatedToUID string + Color string Start time.Time End time.Time @@ -76,6 +78,24 @@ type Alarm struct { type Config struct { Name string ProdID string + Color string +} + +func getCaldavColor(color string) (caldavcolor string) { + if color == "" { + return "" + } + + if !strings.HasPrefix(color, "#") { + color = "#" + color + } + + color += "FF" + + return ` +X-APPLE-CALENDAR-COLOR:` + color + ` +X-OUTLOOK-COLOR:` + color + ` +X-FUNAMBOL-COLOR:` + color } // ParseEvents parses an array of caldav events and gives them back as string @@ -85,7 +105,7 @@ VERSION:2.0 METHOD:PUBLISH X-PUBLISHED-TTL:PT4H X-WR-CALNAME:` + config.Name + ` -PRODID:-//` + config.ProdID + `//EN` +PRODID:-//` + config.ProdID + `//EN` + getCaldavColor(config.Color) for _, e := range events { @@ -102,7 +122,7 @@ PRODID:-//` + config.ProdID + `//EN` caldavevents += ` BEGIN:VEVENT UID:` + e.UID + ` -SUMMARY:` + e.Summary + ` +SUMMARY:` + e.Summary + getCaldavColor(e.Color) + ` DESCRIPTION:` + formattedDescription + ` DTSTAMP:` + makeCalDavTimeFromTimeStamp(e.Timestamp) + ` DTSTART:` + makeCalDavTimeFromTimeStamp(e.Start) + ` @@ -137,7 +157,7 @@ VERSION:2.0 METHOD:PUBLISH X-PUBLISHED-TTL:PT4H X-WR-CALNAME:` + config.Name + ` -PRODID:-//` + config.ProdID + `//EN` +PRODID:-//` + config.ProdID + `//EN` + getCaldavColor(config.Color) for _, t := range todos { if t.UID == "" { @@ -148,7 +168,7 @@ PRODID:-//` + config.ProdID + `//EN` BEGIN:VTODO UID:` + t.UID + ` DTSTAMP:` + makeCalDavTimeFromTimeStamp(t.Timestamp) + ` -SUMMARY:` + t.Summary +SUMMARY:` + t.Summary + getCaldavColor(t.Color) if t.Start.Unix() > 0 { caldavtodos += ` diff --git a/pkg/caldav/caldav_test.go b/pkg/caldav/caldav_test.go index 38ff4cb30..931f866c2 100644 --- a/pkg/caldav/caldav_test.go +++ b/pkg/caldav/caldav_test.go @@ -40,6 +40,7 @@ func TestParseEvents(t *testing.T) { config: &Config{ Name: "test", ProdID: "RandomProdID which is not random", + Color: "ffffff", }, events: []*Event{ { @@ -49,6 +50,7 @@ func TestParseEvents(t *testing.T) { Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()), Start: time.Unix(1543626724, 0).In(config.GetTimeZone()), End: time.Unix(1543627824, 0).In(config.GetTimeZone()), + Color: "affffe", }, { Summary: "Event #2", @@ -72,9 +74,15 @@ METHOD:PUBLISH X-PUBLISHED-TTL:PT4H X-WR-CALNAME:test PRODID:-//RandomProdID which is not random//EN +X-APPLE-CALENDAR-COLOR:#ffffffFF +X-OUTLOOK-COLOR:#ffffffFF +X-FUNAMBOL-COLOR:#ffffffFF BEGIN:VEVENT UID:randommduid SUMMARY:Event #1 +X-APPLE-CALENDAR-COLOR:#affffeFF +X-OUTLOOK-COLOR:#affffeFF +X-FUNAMBOL-COLOR:#affffeFF DESCRIPTION:Lorem Ipsum DTSTAMP:20181201T011204 DTSTART:20181201T011204 @@ -301,6 +309,7 @@ func TestParseTodos(t *testing.T) { config: &Config{ Name: "test", ProdID: "RandomProdID which is not random", + Color: "ffffff", }, todos: []*Todo{ { @@ -309,6 +318,7 @@ func TestParseTodos(t *testing.T) { Dolor sit amet`, UID: "randommduid", Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()), + Color: "affffe", }, }, }, @@ -318,10 +328,16 @@ METHOD:PUBLISH X-PUBLISHED-TTL:PT4H X-WR-CALNAME:test PRODID:-//RandomProdID which is not random//EN +X-APPLE-CALENDAR-COLOR:#ffffffFF +X-OUTLOOK-COLOR:#ffffffFF +X-FUNAMBOL-COLOR:#ffffffFF BEGIN:VTODO UID:randommduid DTSTAMP:20181201T011204 SUMMARY:Todo #1 +X-APPLE-CALENDAR-COLOR:#affffeFF +X-OUTLOOK-COLOR:#affffeFF +X-FUNAMBOL-COLOR:#affffeFF DESCRIPTION:Lorem Ipsum\nDolor sit amet LAST-MODIFIED:00010101T000000 END:VTODO