mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Fixing merge conflict with master and multi-gcal
This commit is contained in:
commit
c08a594d56
51
gcal/client.go
Normal file → Executable file
51
gcal/client.go
Normal file → Executable file
@ -16,6 +16,7 @@ import (
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
@ -47,14 +48,56 @@ func Fetch() (*calendar.Events, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
startTime := fromMidnight().Format(time.RFC3339)
|
||||
eventLimit := int64(wtf.Config.UInt("wtf.mods.gcal.eventCount", 10))
|
||||
events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(startTime).MaxResults(eventLimit).OrderBy("startTime").Do()
|
||||
// Get all user calendars with at the least writing access
|
||||
pageToken := ""
|
||||
var calendarIds []string
|
||||
for {
|
||||
calendarList, err := srv.CalendarList.List().ShowHidden(false).MinAccessRole("writer").PageToken(pageToken).Do()
|
||||
for _, calendarListItem := range calendarList.Items {
|
||||
calendarIds = append(calendarIds, calendarListItem.Id)
|
||||
}
|
||||
|
||||
pageToken = calendarList.NextPageToken
|
||||
if err != nil || pageToken == "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return events, err
|
||||
// Get calendar events
|
||||
var events calendar.Events
|
||||
|
||||
startTime := fromMidnight().Format(time.RFC3339)
|
||||
eventLimit := int64(wtf.Config.UInt("wtf.mods.gcal.eventCount", 10))
|
||||
|
||||
for _, calendarId := range calendarIds {
|
||||
calendarEvents, err := srv.Events.List(calendarId).ShowDeleted(false).TimeMin(startTime).MaxResults(eventLimit).SingleEvents(true).OrderBy("startTime").Do()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
events.Items = append(events.Items, calendarEvents.Items...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Sort events
|
||||
timeDateChooser := func(event *calendar.Event) (time.Time, error) {
|
||||
if len(event.Start.Date) > 0 {
|
||||
return time.Parse("2006-01-02", event.Start.Date)
|
||||
} else {
|
||||
return time.Parse(time.RFC3339, event.Start.DateTime)
|
||||
}
|
||||
}
|
||||
sort.Slice(events.Items, func(i, j int) bool {
|
||||
dateA, _ := timeDateChooser(events.Items[i])
|
||||
dateB, _ := timeDateChooser(events.Items[j])
|
||||
return dateA.Before(dateB)
|
||||
})
|
||||
|
||||
return &events, err
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
5
gcal/widget.go
Normal file → Executable file
5
gcal/widget.go
Normal file → Executable file
@ -129,9 +129,14 @@ func (widget *Widget) eventSummary(event *calendar.Event, conflict bool) string
|
||||
}
|
||||
|
||||
func (widget *Widget) eventTimestamp(event *calendar.Event) string {
|
||||
if len(event.Start.Date) > 0 {
|
||||
startTime, _ := time.Parse("2006-01-02", event.Start.Date)
|
||||
return startTime.Format(wtf.FriendlyDateFormat)
|
||||
} else {
|
||||
startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
|
||||
return startTime.Format(wtf.FriendlyDateTimeFormat)
|
||||
}
|
||||
}
|
||||
|
||||
// eventIsNow returns true if the event is happening now, false if it not
|
||||
func (widget *Widget) eventIsNow(event *calendar.Event) bool {
|
||||
|
1
wtf/utils.go
Normal file → Executable file
1
wtf/utils.go
Normal file → Executable file
@ -13,6 +13,7 @@ import (
|
||||
|
||||
const SimpleDateFormat = "Jan 2"
|
||||
const SimpleTimeFormat = "15:04 MST"
|
||||
const FriendlyDateFormat = "Mon, Jan 2"
|
||||
const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
|
||||
const TimestampFormat = "2006-01-02T15:04:05-0700"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user