From de5113bfa73b4ef85e09418cf5cdbb1f2333cf36 Mon Sep 17 00:00:00 2001 From: Pascal Bleser Date: Thu, 19 Mar 2026 12:25:18 +0100 Subject: [PATCH] groupware: clarify the ContactCard situation --- .../groupware/pkg/groupware/api_contacts.go | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/services/groupware/pkg/groupware/api_contacts.go b/services/groupware/pkg/groupware/api_contacts.go index 566b3fa0f9..fa8a2ed8ea 100644 --- a/services/groupware/pkg/groupware/api_contacts.go +++ b/services/groupware/pkg/groupware/api_contacts.go @@ -9,15 +9,36 @@ import ( ) var ( + // Ideally, we would be using this for sorting, but unfortunately, it is currently not supported by + // Stalwart: https://github.com/stalwartlabs/stalwart/discussions/2918 /* DefaultContactSort = []jmap.ContactCardComparator{ {Property: string(jscontact.ContactCardPropertyName) + "/surname", IsAscending: true}, {Property: string(jscontact.ContactCardPropertyName) + "/given", IsAscending: true}, } + + SupportedContactSortingProperties = []string{ + jscontact.ContactCardPropertyUpdated, + jscontact.ContactCardPropertyCreated, + "surname", + "given", + } + */ + // So we have to settle for this, as only 'updated' and 'created' are supported for now: DefaultContactSort = []jmap.ContactCardComparator{ {Property: jscontact.ContactCardPropertyUpdated, IsAscending: true}, } + + SupportedContactSortingProperties = []string{ + jscontact.ContactCardPropertyUpdated, + jscontact.ContactCardPropertyCreated, + } + + ContactSortingPropertyMapping = map[string]string{ + "surname": string(jscontact.ContactCardPropertyName) + "/surname", + "given": string(jscontact.ContactCardPropertyName) + "/given", + } ) // Get all addressbooks of an account. @@ -105,7 +126,7 @@ func (g *Groupware) GetContactsInAddressbook(w http.ResponseWriter, r *http.Requ InAddressBook: addressBookId, } var sortBy []jmap.ContactCardComparator - if sort, ok, resp := mapSort(accountIds, &req, DefaultContactSort, jscontact.ContactCardProperties, mapContactCardSort); !ok { + if sort, ok, resp := mapSort(accountIds, &req, DefaultContactSort, SupportedContactSortingProperties, mapContactCardSort); !ok { return resp } else { sortBy = sort @@ -225,5 +246,9 @@ func (g *Groupware) DeleteContact(w http.ResponseWriter, r *http.Request) { } func mapContactCardSort(s SortCrit) jmap.ContactCardComparator { - return jmap.ContactCardComparator{Property: s.Attribute, IsAscending: s.Ascending} + attr := s.Attribute + if mapped, ok := ContactSortingPropertyMapping[s.Attribute]; ok { + attr = mapped + } + return jmap.ContactCardComparator{Property: attr, IsAscending: s.Ascending} }