Documentation ¶
Overview ¶
package extensions contains the interface and concrete implementations for all sliding sync extensions
Index ¶
- func ExtensionEnabled(r GenericRequest) bool
- type AccountDataRequest
- type AccountDataResponse
- type Context
- type Core
- type E2EEDeviceList
- type E2EEFetcher
- type E2EERequest
- type E2EEResponse
- type GenericRequest
- type GenericResponse
- type Handler
- type HandlerInterface
- type ReceiptsRequest
- type ReceiptsResponse
- type Request
- type Response
- type ToDeviceRequest
- type ToDeviceResponse
- type TypingRequest
- type TypingResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtensionEnabled ¶ added in v0.99.1
func ExtensionEnabled(r GenericRequest) bool
Types ¶
type AccountDataRequest ¶
type AccountDataRequest struct {
Core
}
Client created request params
func (*AccountDataRequest) AppendLive ¶ added in v0.99.1
func (*AccountDataRequest) Name ¶ added in v0.99.1
func (r *AccountDataRequest) Name() string
func (*AccountDataRequest) ProcessInitial ¶ added in v0.99.1
func (r *AccountDataRequest) ProcessInitial(ctx context.Context, res *Response, extCtx Context)
type AccountDataResponse ¶
type AccountDataResponse struct { Global []json.RawMessage `json:"global,omitempty"` Rooms map[string][]json.RawMessage `json:"rooms,omitempty"` }
Server response
func (*AccountDataResponse) HasData ¶
func (r *AccountDataResponse) HasData(isInitial bool) bool
type Context ¶ added in v0.99.1
type Context struct { *Handler // RoomIDToTimeline is a map from room IDs to slices of event IDs. The keys are the // rooms which // - have seen new events since the last sync request, and // - the client is subscribed to (via a list or a room subscription). // The values are the event IDs at the end of the room "timeline", ordered from // oldest to newest, as determined by the core sliding sync protocol. // TODO: can the timelines be "gappy" like a v2 sync timeline? RoomIDToTimeline map[string][]string // IsInitial is true if this sync is requesting a snapshot of current client state // (pos = 0, "initial sync") and false otherwise (pos > 0, "incremental sync"). IsInitial bool UserID string DeviceID string // Map from room IDs to list names. Keys are the room IDs of all rooms currently // visible in at least one sliding window. Values are the names of the lists that // enclose those sliding windows. Values should be nonnil and nonempty, and may // contain multiple list names. RoomIDsToLists map[string][]string // AllLists is the slice of list names provided to the Sliding Window API. AllLists []string // AllSubscribedRooms is the slice of room IDs provided to the Room Subscription API. AllSubscribedRooms []string }
Context is a summary of useful information about the sync3.Request and the state of the requester's connection.
type Core ¶ added in v0.99.2
type Core struct { // All fields are optional, with nil meaning "not specified". Enabled *bool `json:"enabled"` Lists []string `json:"lists"` Rooms []string `json:"rooms"` }
mixin for managing the flags reserved by the Core API
func (*Core) ApplyDelta ¶ added in v0.99.2
func (r *Core) ApplyDelta(gnext GenericRequest)
func (*Core) InterpretAsInitial ¶ added in v0.99.6
func (r *Core) InterpretAsInitial()
func (*Core) RoomInScope ¶ added in v0.99.2
RoomInScope determines whether a given room ought to be processed by this extension, according to the "core" extension scoping logic. Extensions are free to suppress updates for a room based on additional criteria.
type E2EEDeviceList ¶
type E2EEFetcher ¶ added in v0.99.0
type E2EEFetcher interface {
DeviceData(context context.Context, userID, deviceID string, isInitial bool) *internal.DeviceData
}
Fetcher used by the E2EE extension
type E2EERequest ¶
type E2EERequest struct {
Core
}
Client created request params
func (*E2EERequest) AppendLive ¶ added in v0.99.1
func (*E2EERequest) Name ¶ added in v0.99.1
func (r *E2EERequest) Name() string
func (*E2EERequest) ProcessInitial ¶ added in v0.99.1
func (r *E2EERequest) ProcessInitial(ctx context.Context, res *Response, extCtx Context)
type E2EEResponse ¶
type E2EEResponse struct { OTKCounts map[string]int `json:"device_one_time_keys_count,omitempty"` DeviceLists *E2EEDeviceList `json:"device_lists,omitempty"` FallbackKeyTypes []string `json:"device_unused_fallback_key_types,omitempty"` }
Server response
func (*E2EEResponse) HasData ¶
func (r *E2EEResponse) HasData(isInitial bool) bool
type GenericRequest ¶ added in v0.99.1
type GenericRequest interface { // Name provides a name to identify the kind of request. At present, it's only // used to name opentracing spans; this isn't end-user visible. Name() string // Returns the value of the `enabled` JSON key. nil for "not specified". IsEnabled() *bool // Returns the value of the `lists` JSON key. nil for "not specified". OnlyLists() []string // Returns the value of the `rooms` JSON key. nil for "not specified". OnlyRooms() []string // InterpretAsInitial interprets this as an initial request rather than a delta, and // overwrites fields accordingly. This can be useful when fields have default // values, but is a little ugly. Use sparingly. InterpretAsInitial() // Overwrite fields in the request by side-effecting on this struct. ApplyDelta(next GenericRequest) // ProcessInitial provides a means for extensions to return data to clients immediately. // If an implementation wants to do so, put the response into *Response (and ensure // that GenericResponse.HasData returns true). // // This is called for every request before going into a live stream loop. By "every // request" we mean both initial and incremental syncs; this function gets call // multiple times over the lifetime of a connection. (Read Context.IsInitial to see // if we are serving an initial or incremental sync.) ProcessInitial(ctx context.Context, res *Response, extCtx Context) // Process a live event, /aggregating/ the response in *Response. This function can be called // multiple times per sync loop as the conn buffer is consumed. AppendLive(ctx context.Context, res *Response, extCtx Context, up caches.Update) }
type GenericResponse ¶ added in v0.99.1
type GenericResponse interface { // HasData determines if there is enough data in the response for it to be // meaningful or useful for the client. If so, we eagerly return this response // (even if we are aware of other updates). The parameter isInitial is true if and // only if this response is to an initial sync request; this allows the // implementation to send out a "fuller" update to an initial sync than it would // for an incremental sync. HasData(isInitial bool) bool }
type Handler ¶
type Handler struct { Store *state.Storage E2EEFetcher E2EEFetcher GlobalCache *caches.GlobalCache }
type HandlerInterface ¶
type ReceiptsRequest ¶
type ReceiptsRequest struct {
Core
}
Client created request params
func (*ReceiptsRequest) AppendLive ¶ added in v0.99.1
func (*ReceiptsRequest) Name ¶ added in v0.99.1
func (r *ReceiptsRequest) Name() string
func (*ReceiptsRequest) ProcessInitial ¶ added in v0.99.1
func (r *ReceiptsRequest) ProcessInitial(ctx context.Context, res *Response, extCtx Context)
type ReceiptsResponse ¶
type ReceiptsResponse struct { // room_id -> m.receipt ephemeral event Rooms map[string]json.RawMessage `json:"rooms,omitempty"` }
Server response
func (*ReceiptsResponse) HasData ¶
func (r *ReceiptsResponse) HasData(isInitial bool) bool
type Request ¶
type Request struct { ToDevice *ToDeviceRequest `json:"to_device"` E2EE *E2EERequest `json:"e2ee"` AccountData *AccountDataRequest `json:"account_data"` Typing *TypingRequest `json:"typing"` Receipts *ReceiptsRequest `json:"receipts"` }
Request is the JSON request body under 'extensions'.
To add new extensions, add a field here and return it in fields() whilst setting it correctly in setFields().
func (Request) ApplyDelta ¶
ApplyDelta applies the `next` request as a delta atop the previous Request r, and returns the result as a new Request.
func (Request) EnabledExtensions ¶ added in v0.99.1
func (r Request) EnabledExtensions() (exts []GenericRequest)
func (*Request) InterpretAsInitial ¶ added in v0.99.6
func (r *Request) InterpretAsInitial()
type Response ¶
type Response struct { ToDevice *ToDeviceResponse `json:"to_device,omitempty"` E2EE *E2EEResponse `json:"e2ee,omitempty"` AccountData *AccountDataResponse `json:"account_data,omitempty"` Typing *TypingResponse `json:"typing,omitempty"` Receipts *ReceiptsResponse `json:"receipts,omitempty"` }
Response represents the top-level `extensions` key in the JSON response.
To add a new extension, add a field here and in fields().
type ToDeviceRequest ¶
type ToDeviceRequest struct { Core Limit int `json:"limit"` // max number of to-device messages per response Since string `json:"since"` // since token }
Client created request params
func (*ToDeviceRequest) AppendLive ¶ added in v0.99.1
func (*ToDeviceRequest) ApplyDelta ¶
func (r *ToDeviceRequest) ApplyDelta(gnext GenericRequest)
func (*ToDeviceRequest) Name ¶ added in v0.99.1
func (r *ToDeviceRequest) Name() string
func (*ToDeviceRequest) ProcessInitial ¶ added in v0.99.1
func (r *ToDeviceRequest) ProcessInitial(ctx context.Context, res *Response, extCtx Context)
type ToDeviceResponse ¶
type ToDeviceResponse struct { NextBatch string `json:"next_batch"` Events []json.RawMessage `json:"events,omitempty"` }
Server response
func (*ToDeviceResponse) HasData ¶
func (r *ToDeviceResponse) HasData(isInitial bool) bool
type TypingRequest ¶
type TypingRequest struct {
Core
}
Client created request params
func (*TypingRequest) AppendLive ¶ added in v0.99.1
func (*TypingRequest) Name ¶ added in v0.99.1
func (r *TypingRequest) Name() string
func (*TypingRequest) ProcessInitial ¶ added in v0.99.1
func (r *TypingRequest) ProcessInitial(ctx context.Context, res *Response, extCtx Context)
type TypingResponse ¶
type TypingResponse struct {
Rooms map[string]json.RawMessage `json:"rooms,omitempty"`
}
Server response
func (*TypingResponse) HasData ¶
func (r *TypingResponse) HasData(isInitial bool) bool