Hi there!
I spent a while trying to figure out why JavaScript and Go clients were
returning different results for the same query, turns out this was the
root cause.
Relevant snippet from the JMAP Core spec (https://jmap.io/spec-
core.html):
"""
isAscending: Boolean (optional; default: true) If true, sort in
ascending order. If false, reverse the comparator’s results to sort in
descending order.
"""
Brandon Sprague (2):
Fix an issue with `isAscending`
Fix tests
mail/email/sort.go | 2 +-
mail/emailsubmission/sort.go | 2 +-
mail/mailbox/query_test.go | 2 +-
mail/mailbox/sort.go | 2 +-
mail/mailbox/sort_test.go | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
--
2.38.5
Thanks!
One thing that didn't occur to me until after is that this
unfortunately isn't a backwards compatible change. Since the library
is pre-1.0.0, it's probably fine, but worth noting. Anywhere that
'IsAscending' is not specified will now sort in the opposite direction
(assuming a compliant JMAP server).
The other alternative would be to make 'isAscending' a *bool, but
that's just backwards-incompatible in a different way, causing
compilation errors for anyone currently specifying 'IsAscending'. That
approach has the benefit of failing loudly rather than quietly though.
From: Brandon Sprague <brandon@sprague.mx>
According to the spec, it defaults to true. But since `omitempty` was set, the absence == the zero value == false, so it ends up true in the API.
---
Hey Brandon -
Thanks for the patch! Just so I am clear on where this is coming up...if you are
a client and set sortAscending to false, it will be empty in JSON thus
defaulting to true...effectively making it impossible to sort descending. Do I
have that right?
mail/email/sort.go | 2 +-mail/emailsubmission/sort.go | 2 +-mail/mailbox/sort.go | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/mail/email/sort.go b/mail/email/sort.go
index f28e396..ddfa791 100644
--- a/mail/email/sort.go+++ b/mail/email/sort.go
@@ -9,7 +9,7 @@ type SortComparator struct {
Keyword string `json:"keyword,omitempty"`
- IsAscending bool `json:"isAscending,omitempty"`+ IsAscending bool `json:"isAscending"` Collation jmap.CollationAlgo `json:"collation,omitempty"`
}
diff --git a/mail/emailsubmission/sort.go b/mail/emailsubmission/sort.go
index 04d6174..38083a9 100644
--- a/mail/emailsubmission/sort.go+++ b/mail/emailsubmission/sort.go
@@ -5,7 +5,7 @@ import "git.sr.ht/~rockorager/go-jmap"
type SortComparator struct {
Property string `json:"property,omitempty"`
- IsAscending bool `json:"isAscending,omitempty"`+ IsAscending bool `json:"isAscending"` Collation jmap.CollationAlgo `json:"collation,omitempty"`
}
diff --git a/mail/mailbox/sort.go b/mail/mailbox/sort.go
index fb07b6d..560eea8 100644
--- a/mail/mailbox/sort.go+++ b/mail/mailbox/sort.go
@@ -7,7 +7,7 @@ type SortComparator struct {
Property string `json:"property,omitempty"`
// If true, sort in ascending order.
- IsAscending bool `json:"isAscending,omitempty"`+ IsAscending bool `json:"isAscending"` // The identifier, as registered in the collation registry defined in
// RFC4790, for the algorithm to use when comparing the order of
--
2.38.5