Files
opencloud/pkg/jmap/jmap_client.go
Pascal Bleser 5acbde1d97 feat(groupware): add fetching all mailboxes for all accounts
* add URL to retrieve all the mailboxes for all the accounts of a user,
   as a first use-case for an all-accounts operation, as
   /accounts/all/mailboxes

 * add URL to retrieve mailbox changes for all the mailboxes of all the
   accounts of a user, as a first use-case for an all-accounts
   operation, as /accounts/all/mailboxes/changes

 * change the defaultAccountId from '*' to '_', as '*' rather indicates
   "all" than "default", and we might want to use that for "all
   accounts" operations in the future

 * refactor(groupware): remove the accountId parameter from the logger()
   function, as it is not used anyways, but also confusing for
   operations that support multiple account ids
2026-04-03 15:40:07 +02:00

65 lines
1.7 KiB
Go

package jmap
import (
"io"
"net/url"
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/rs/zerolog"
)
type Client struct {
session SessionClient
api ApiClient
blob BlobClient
sessionEventListeners *eventListeners[SessionEventListener]
io.Closer
}
var _ io.Closer = &Client{}
func (j *Client) Close() error {
return j.api.Close()
}
func NewClient(session SessionClient, api ApiClient, blob BlobClient) Client {
return Client{
session: session,
api: api,
blob: blob,
sessionEventListeners: newEventListeners[SessionEventListener](),
}
}
func (j *Client) AddSessionEventListener(listener SessionEventListener) {
j.sessionEventListeners.add(listener)
}
func (j *Client) onSessionOutdated(session *Session, newSessionState SessionState) {
j.sessionEventListeners.signal(func(listener SessionEventListener) {
listener.OnSessionOutdated(session, newSessionState)
})
}
// Retrieve JMAP well-known data from the Stalwart server and create a Session from that.
func (j *Client) FetchSession(sessionUrl *url.URL, username string, logger *log.Logger) (Session, Error) {
wk, err := j.session.GetSession(sessionUrl, username, logger)
if err != nil {
return Session{}, err
}
return newSession(wk)
}
func (j *Client) logger(operation string, _ *Session, logger *log.Logger) *log.Logger {
l := logger.With().Str(logOperation, operation)
return log.From(l)
}
func (j *Client) loggerParams(operation string, _ *Session, logger *log.Logger, params func(zerolog.Context) zerolog.Context) *log.Logger {
l := logger.With().Str(logOperation, operation)
if params != nil {
l = params(l)
}
return log.From(l)
}