mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Make use of multiple calendars in GCal module optional
The change in PR #211 to make the GCal module use all calendars writable to the user is not desirable in all situations. At my organization, I have write access to calendars for conference rooms, for people's OOO events, etc. that fill my screen, obscuring the events on my own calendar. This change puts the behavior in that change behind a new config flag, `wtf.mods.gcal.multiCalendar`. It defaults to `false`, but feel free to change that if you think this is behavior that most users would want (I tend to default towards preserving existing behavior, in this case from before that change).
This commit is contained in:
parent
8a0ace3837
commit
4c70cae64b
@ -48,23 +48,7 @@ func Fetch() (*calendar.Events, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
calendarIds, err := getCalendarIdList(srv)
|
||||
|
||||
// Get calendar events
|
||||
var events calendar.Events
|
||||
@ -179,3 +163,33 @@ func saveToken(file string, token *oauth2.Token) {
|
||||
|
||||
json.NewEncoder(f).Encode(token)
|
||||
}
|
||||
|
||||
func getCalendarIdList(srv *calendar.Service) ([]string, error) {
|
||||
// Return single calendar if settings specify we should
|
||||
if !wtf.Config.UBool("wtf.mods.gcal.multiCalendar", false) {
|
||||
id, err := srv.CalendarList.Get("primary").Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []string{id.Id}, nil
|
||||
}
|
||||
|
||||
// Get all user calendars with at the least writing access
|
||||
var calendarIds []string
|
||||
var pageToken string
|
||||
for {
|
||||
calendarList, err := srv.CalendarList.List().ShowHidden(false).MinAccessRole("writer").PageToken(pageToken).Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, calendarListItem := range calendarList.Items {
|
||||
calendarIds = append(calendarIds, calendarListItem.Id)
|
||||
}
|
||||
|
||||
pageToken = calendarList.NextPageToken
|
||||
if pageToken == "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
return calendarIds, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user