types

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 12 Imported by: 64

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// This error is returned when parsing sync tokens if the token is invalid. Callers can use this
	// error to detect whether to 400 or 401 the client. It is recommended to 401 them to force a
	// logout.
	ErrMalformedSyncToken = errors.New("malformed sync token")
)

Functions

This section is empty.

Types

type InviteResponse

type InviteResponse struct {
	InviteState struct {
		Events []json.RawMessage `json:"events"`
	} `json:"invite_state"`
}

InviteResponse represents a /sync response for a room which is under the 'invite' key.

func NewInviteResponse

func NewInviteResponse(event *gomatrixserverlib.HeaderedEvent) *InviteResponse

NewInviteResponse creates an empty response with initialised arrays.

type JoinResponse

type JoinResponse struct {
	State struct {
		Events []gomatrixserverlib.ClientEvent `json:"events"`
	} `json:"state"`
	Timeline struct {
		Events    []gomatrixserverlib.ClientEvent `json:"events"`
		Limited   bool                            `json:"limited"`
		PrevBatch *TopologyToken                  `json:"prev_batch,omitempty"`
	} `json:"timeline"`
	Ephemeral struct {
		Events []gomatrixserverlib.ClientEvent `json:"events"`
	} `json:"ephemeral"`
	AccountData struct {
		Events []gomatrixserverlib.ClientEvent `json:"events"`
	} `json:"account_data"`
}

JoinResponse represents a /sync response for a room which is under the 'join' or 'peek' key.

func NewJoinResponse

func NewJoinResponse() *JoinResponse

NewJoinResponse creates an empty response with initialised arrays.

type LeaveResponse

type LeaveResponse struct {
	State struct {
		Events []gomatrixserverlib.ClientEvent `json:"events"`
	} `json:"state"`
	Timeline struct {
		Events    []gomatrixserverlib.ClientEvent `json:"events"`
		Limited   bool                            `json:"limited"`
		PrevBatch *TopologyToken                  `json:"prev_batch,omitempty"`
	} `json:"timeline"`
}

LeaveResponse represents a /sync response for a room which is under the 'leave' key.

func NewLeaveResponse

func NewLeaveResponse() *LeaveResponse

NewLeaveResponse creates an empty response with initialised arrays.

type Peek

type Peek struct {
	RoomID  string
	New     bool
	Deleted bool
}

type PeekingDevice

type PeekingDevice struct {
	UserID   string
	DeviceID string
}

type PrevEventRef

type PrevEventRef struct {
	PrevContent   json.RawMessage `json:"prev_content"`
	ReplacesState string          `json:"replaces_state"`
	PrevSender    string          `json:"prev_sender"`
}

PrevEventRef represents a reference to a previous event in a state event upgrade

type Range

type Range struct {
	// From is the position the client has already received.
	From StreamPosition
	// To is the position the client is going towards.
	To StreamPosition
	// True if the client is going backwards
	Backwards bool
}

Range represents a range between two stream positions.

func (*Range) High

func (r *Range) High() StreamPosition

High returns the high number of the range This represents the position the client is going towards and hence is inclusive.

func (*Range) Low

func (r *Range) Low() StreamPosition

Low returns the low number of the range. This represents the position the client already has and hence is exclusive.

type Response

type Response struct {
	NextBatch   StreamingToken `json:"next_batch"`
	AccountData struct {
		Events []gomatrixserverlib.ClientEvent `json:"events,omitempty"`
	} `json:"account_data"`
	Presence struct {
		Events []gomatrixserverlib.ClientEvent `json:"events,omitempty"`
	} `json:"presence"`
	Rooms struct {
		Join   map[string]JoinResponse   `json:"join"`
		Peek   map[string]JoinResponse   `json:"peek"`
		Invite map[string]InviteResponse `json:"invite"`
		Leave  map[string]LeaveResponse  `json:"leave"`
	} `json:"rooms"`
	ToDevice struct {
		Events []gomatrixserverlib.SendToDeviceEvent `json:"events"`
	} `json:"to_device"`
	DeviceLists struct {
		Changed []string `json:"changed,omitempty"`
		Left    []string `json:"left,omitempty"`
	} `json:"device_lists"`
	DeviceListsOTKCount map[string]int `json:"device_one_time_keys_count,omitempty"`
}

Response represents a /sync API response. See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync

func NewResponse

func NewResponse() *Response

NewResponse creates an empty response with initialised maps.

func (*Response) IsEmpty

func (r *Response) IsEmpty() bool

IsEmpty returns true if the response is empty, i.e. used to decided whether to return the response immediately to the client or to wait for more data.

type SendToDeviceEvent

type SendToDeviceEvent struct {
	gomatrixserverlib.SendToDeviceEvent
	ID       StreamPosition
	UserID   string
	DeviceID string
}

type StateDelta added in v0.3.5

type StateDelta struct {
	RoomID      string
	StateEvents []*gomatrixserverlib.HeaderedEvent
	Membership  string
	// The PDU stream position of the latest membership event for this user, if applicable.
	// Can be 0 if there is no membership event in this delta.
	MembershipPos StreamPosition
}

type StreamEvent

type StreamEvent struct {
	*gomatrixserverlib.HeaderedEvent
	StreamPosition  StreamPosition
	TransactionID   *api.TransactionID
	ExcludeFromSync bool
}

StreamEvent is the same as gomatrixserverlib.Event but also has the PDU stream position for this event.

type StreamPosition

type StreamPosition int64

StreamPosition represents the offset in the sync stream a client is at.

type StreamProvider added in v0.3.5

type StreamProvider interface {
	Setup()

	// Advance will update the latest position of the stream based on
	// an update and will wake callers waiting on StreamNotifyAfter.
	Advance(latest StreamPosition)

	// CompleteSync will update the response to include all updates as needed
	// for a complete sync. It will always return immediately.
	CompleteSync(ctx context.Context, req *SyncRequest) StreamPosition

	// IncrementalSync will update the response to include all updates between
	// the from and to sync positions. It will always return immediately,
	// making no changes if the range contains no updates.
	IncrementalSync(ctx context.Context, req *SyncRequest, from, to StreamPosition) StreamPosition

	// LatestPosition returns the latest stream position for this stream.
	LatestPosition(ctx context.Context) StreamPosition
}

type StreamingToken

type StreamingToken struct {
	PDUPosition          StreamPosition
	TypingPosition       StreamPosition
	ReceiptPosition      StreamPosition
	SendToDevicePosition StreamPosition
	InvitePosition       StreamPosition
	AccountDataPosition  StreamPosition
	DeviceListPosition   StreamPosition
}

func NewStreamTokenFromString

func NewStreamTokenFromString(tok string) (token StreamingToken, err error)

func (*StreamingToken) ApplyUpdates added in v0.3.4

func (t *StreamingToken) ApplyUpdates(other StreamingToken)

ApplyUpdates applies any changes from the supplied StreamingToken. If the supplied streaming token contains any positions that are not 0, they are considered updates and will overwrite the value in the token.

func (*StreamingToken) IsAfter

func (t *StreamingToken) IsAfter(other StreamingToken) bool

IsAfter returns true if ANY position in this token is greater than `other`.

func (*StreamingToken) IsEmpty added in v0.3.4

func (t *StreamingToken) IsEmpty() bool

func (StreamingToken) MarshalText added in v0.3.4

func (s StreamingToken) MarshalText() ([]byte, error)

This will be used as a fallback by json.Marshal.

func (StreamingToken) String

func (t StreamingToken) String() string

func (*StreamingToken) UnmarshalText added in v0.3.4

func (s *StreamingToken) UnmarshalText(text []byte) (err error)

This will be used as a fallback by json.Unmarshal.

func (*StreamingToken) WithUpdates

func (t *StreamingToken) WithUpdates(other StreamingToken) StreamingToken

WithUpdates returns a copy of the StreamingToken with updates applied from another StreamingToken. If the latter StreamingToken contains a field that is not 0, it is considered an update, and its value will replace the corresponding value in the StreamingToken on which WithUpdates is called. If the other token has a log, they will replace any existing log on this token.

type SyncRequest added in v0.3.5

type SyncRequest struct {
	Context       context.Context
	Log           *logrus.Entry
	Device        *userapi.Device
	Response      *Response
	Filter        gomatrixserverlib.Filter
	Since         StreamingToken
	Timeout       time.Duration
	WantFullState bool

	// Updated by the PDU stream.
	Rooms map[string]string
}

type SyncTokenType

type SyncTokenType string

SyncTokenType represents the type of a sync token. It can be either "s" (representing a position in the whole stream of events) or "t" (representing a position in a room's topology/depth).

const (
	// SyncTokenTypeStream represents a position in the server's whole
	// stream of events
	SyncTokenTypeStream SyncTokenType = "s"
	// SyncTokenTypeTopology represents a position in a room's topology.
	SyncTokenTypeTopology SyncTokenType = "t"
)

type TopologyToken

type TopologyToken struct {
	Depth       StreamPosition
	PDUPosition StreamPosition
}

func NewTopologyTokenFromString

func NewTopologyTokenFromString(tok string) (token TopologyToken, err error)

func (*TopologyToken) Decrement

func (t *TopologyToken) Decrement()

Decrement the topology token to one event earlier.

func (TopologyToken) MarshalText added in v0.3.4

func (t TopologyToken) MarshalText() ([]byte, error)

This will be used as a fallback by json.Marshal.

func (*TopologyToken) StreamToken

func (t *TopologyToken) StreamToken() StreamingToken

func (TopologyToken) String

func (t TopologyToken) String() string

func (*TopologyToken) UnmarshalText added in v0.3.4

func (t *TopologyToken) UnmarshalText(text []byte) (err error)

This will be used as a fallback by json.Unmarshal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL