Files
opencloud/pkg/jmap/jmap_client.go
Pascal Bleser c8660a635e groupware: add /bootstrap
* add a GET /accounts/{a}/boostrap URI that delivers the same as GET /
   but also mailboxes for a given account, in case the UI remembers the
   last used account identifier, to avoid an additional roundtrip

 * streamline the use of simpleError()

 * add logging of errors at the calling site

 * add logging of evictions of Sessions from the cache

 * change default Session cache TTL to 5min instead of 30sec
2026-04-13 16:39:51 +02:00

68 lines
1.9 KiB
Go

package jmap
import (
"io"
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/rs/zerolog"
)
type Client struct {
wellKnown SessionClient
api ApiClient
blob BlobClient
sessionEventListeners *eventListeners[SessionEventListener]
io.Closer
}
func (j *Client) Close() error {
return j.api.Close()
}
func NewClient(wellKnown SessionClient, api ApiClient, blob BlobClient) Client {
return Client{
wellKnown: wellKnown,
api: api,
blob: blob,
sessionEventListeners: newEventListeners[SessionEventListener](),
}
}
func (j *Client) AddSessionEventListener(listener SessionEventListener) {
j.sessionEventListeners.add(listener)
}
func (j *Client) onSessionOutdated(session *Session, newSessionState string) {
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(username string, logger *log.Logger) (Session, Error) {
wk, err := j.wellKnown.GetSession(username, logger)
if err != nil {
return Session{}, err
}
return newSession(wk)
}
func (j *Client) logger(accountId string, operation string, session *Session, logger *log.Logger) *log.Logger {
l := logger.With().Str(logOperation, operation).Str(logUsername, session.Username)
if accountId != "" {
l = l.Str(logAccountId, accountId)
}
return log.From(l)
}
func (j *Client) loggerParams(accountId string, operation string, session *Session, logger *log.Logger, params func(zerolog.Context) zerolog.Context) *log.Logger {
l := logger.With().Str(logOperation, operation).Str(logUsername, session.Username)
if accountId != "" {
l = l.Str(logAccountId, accountId)
}
if params != nil {
l = params(l)
}
return log.From(l)
}