types

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: Apache-2.0 Imports: 9 Imported by: 64

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSyncTokenType is returned when an attempt at creating a
	// new instance of SyncToken with an invalid type (i.e. neither "s"
	// nor "t").
	ErrInvalidSyncTokenType = fmt.Errorf("Sync token has an unknown prefix (should be either s or t)")
	// ErrInvalidSyncTokenLen is returned when the pagination token is an
	// invalid length
	ErrInvalidSyncTokenLen = fmt.Errorf("Sync token has an invalid length")
)

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 string                          `json:"prev_batch"`
	} `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 string                          `json:"prev_batch"`
	} `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 LogPosition

type LogPosition struct {
	Partition int32
	Offset    int64
}

LogPosition represents the offset in a Kafka log a client is at.

func (*LogPosition) IsAfter

func (p *LogPosition) IsAfter(lp *LogPosition) bool

IsAfter returns true if this position is after `lp`.

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   string `json:"next_batch"`
	AccountData struct {
		Events []gomatrixserverlib.ClientEvent `json:"events"`
	} `json:"account_data,omitempty"`
	Presence struct {
		Events []gomatrixserverlib.ClientEvent `json:"events"`
	} `json:"presence,omitempty"`
	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,omitempty"`
	DeviceListsOTKCount map[string]int `json:"device_one_time_keys_count"`
}

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          SendToDeviceNID
	UserID      string
	DeviceID    string
	SentByToken *StreamingToken
}

type SendToDeviceNID

type SendToDeviceNID int

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 StreamingToken

type StreamingToken struct {
	// contains filtered or unexported fields
}

func NewStreamToken

func NewStreamToken(pduPos, eduPos StreamPosition, logs map[string]*LogPosition) StreamingToken

NewStreamToken creates a new sync token for /sync

func NewStreamTokenFromString

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

func (*StreamingToken) EDUPosition

func (t *StreamingToken) EDUPosition() StreamPosition

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) Log

func (t *StreamingToken) Log(name string) *LogPosition

func (*StreamingToken) PDUPosition

func (t *StreamingToken) PDUPosition() StreamPosition

func (*StreamingToken) SetLog

func (t *StreamingToken) SetLog(name string, lp *LogPosition)

func (*StreamingToken) String

func (t *StreamingToken) String() string

func (*StreamingToken) WithUpdates

func (t *StreamingToken) WithUpdates(other StreamingToken) (ret 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 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 {
	// contains filtered or unexported fields
}

func NewTopologyToken

func NewTopologyToken(depth, streamPos StreamPosition) TopologyToken

NewTopologyToken creates a new sync token for /messages

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) Depth

func (t *TopologyToken) Depth() StreamPosition

func (*TopologyToken) PDUPosition

func (t *TopologyToken) PDUPosition() StreamPosition

func (*TopologyToken) StreamToken

func (t *TopologyToken) StreamToken() StreamingToken

func (*TopologyToken) String

func (t *TopologyToken) String() string

Jump to

Keyboard shortcuts

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