types

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 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 IgnoredUsers added in v0.8.0

type IgnoredUsers struct {
	List map[string]interface{} `json:"ignored_users"`
}

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 {
	Summary struct {
		Heroes             []string `json:"m.heroes,omitempty"`
		JoinedMemberCount  *int     `json:"m.joined_member_count,omitempty"`
		InvitedMemberCount *int     `json:"m.invited_member_count,omitempty"`
	} `json:"summary"`
	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"`
	UnreadNotifications struct {
		HighlightCount    int `json:"highlight_count"`
		NotificationCount int `json:"notification_count"`
	} `json:"unread_notifications"`
}

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 OutputReceiptEvent added in v0.8.0

type OutputReceiptEvent struct {
	UserID    string                      `json:"user_id"`
	RoomID    string                      `json:"room_id"`
	EventID   string                      `json:"event_id"`
	Type      string                      `json:"type"`
	Timestamp gomatrixserverlib.Timestamp `json:"timestamp"`
}

OutputReceiptEvent is an entry in the receipt output kafka log

type OutputSendToDeviceEvent added in v0.8.0

type OutputSendToDeviceEvent struct {
	UserID   string `json:"user_id"`
	DeviceID string `json:"device_id"`
	gomatrixserverlib.SendToDeviceEvent
}

OutputSendToDeviceEvent is an entry in the send-to-device output kafka log. This contains the full event content, along with the user ID and device ID to which it is destined.

type Peek

type Peek struct {
	RoomID  string
	New     bool
	Deleted bool
}

type PeekingDevice

type PeekingDevice struct {
	UserID   string
	DeviceID string
}

type Presence added in v0.8.0

type Presence uint8
const (
	PresenceUnknown     Presence = iota
	PresenceUnavailable          // unavailable
	PresenceOnline               // online
	PresenceOffline              // offline
)

func PresenceFromString added in v0.8.0

func PresenceFromString(input string) (Presence, bool)

PresenceFromString returns the integer representation of the given input presence. Returns false for ok, if input is not a valid presence value.

func (Presence) String added in v0.8.0

func (p Presence) String() string

type PresenceClientResponse added in v0.8.0

type PresenceClientResponse struct {
	CurrentlyActive *bool   `json:"currently_active,omitempty"`
	LastActiveAgo   int64   `json:"last_active_ago,omitempty"`
	Presence        string  `json:"presence"`
	StatusMsg       *string `json:"status_msg,omitempty"`
}

type PresenceInternal added in v0.8.0

type PresenceInternal struct {
	ClientFields PresenceClientResponse
	StreamPos    StreamPosition              `json:"-"`
	UserID       string                      `json:"-"`
	LastActiveTS gomatrixserverlib.Timestamp `json:"-"`
	Presence     Presence                    `json:"-"`
}

func (*PresenceInternal) CurrentlyActive added in v0.8.0

func (p *PresenceInternal) CurrentlyActive() bool

CurrentlyActive returns the current active state.

func (*PresenceInternal) Equals added in v0.8.0

func (p1 *PresenceInternal) Equals(p2 *PresenceInternal) bool

Equals compares p1 with p2.

func (*PresenceInternal) LastActiveAgo added in v0.8.0

func (p *PresenceInternal) LastActiveAgo() int64

LastActiveAgo returns the time since the LastActiveTS in milliseconds.

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 ReadUpdate added in v0.6.5

type ReadUpdate struct {
	UserID    string         `json:"user_id"`
	RoomID    string         `json:"room_id"`
	Read      StreamPosition `json:"read,omitempty"`
	FullyRead StreamPosition `json:"fully_read,omitempty"`
}

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) HasUpdates added in v0.8.6

func (r *Response) HasUpdates() bool

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 StreamedEvent added in v0.6.5

type StreamedEvent struct {
	Event          *gomatrixserverlib.HeaderedEvent `json:"event"`
	StreamPosition StreamPosition                   `json:"stream_position"`
}

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

type StreamingToken

type StreamingToken struct {
	PDUPosition              StreamPosition
	TypingPosition           StreamPosition
	ReceiptPosition          StreamPosition
	SendToDevicePosition     StreamPosition
	InvitePosition           StreamPosition
	AccountDataPosition      StreamPosition
	DeviceListPosition       StreamPosition
	NotificationDataPosition StreamPosition
	PresencePosition         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
	// Updated by the PDU stream.
	IgnoredUsers IgnoredUsers
}

func (*SyncRequest) IsRoomPresent added in v0.8.2

func (r *SyncRequest) IsRoomPresent(roomID string) bool

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