carddav: paging support

This commit is contained in:
emersion 2017-09-04 11:46:14 +02:00
parent 38e625fbe2
commit e3ec66ed0f
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 21 additions and 11 deletions

View File

@ -64,19 +64,29 @@ func (ab *addressBook) ListAddressObjects() ([]carddav.AddressObject, error) {
return aos, nil
}
// TODO: paging support
total, contacts, err := ab.c.ListContactsExport(0, 0)
var aos []carddav.AddressObject
page := 0
for {
total, contacts, err := ab.c.ListContactsExport(page, 0)
if err != nil {
return nil, err
}
ab.total = total
aos := make([]carddav.AddressObject, len(contacts))
for i, contact := range contacts {
if aos == nil {
aos = make([]carddav.AddressObject, 0, total)
}
for _, contact := range contacts {
ao := &addressObject{c: ab.c, contact: contact}
ab.cache[contact.ID] = ao
aos[i] = ao
aos = append(aos, ao)
}
if len(aos) == total || len(contacts) == 0 {
break
}
page++
}
return aos, nil