types

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 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 ClientEvents added in v0.10.2

type ClientEvents struct {
	Events []gomatrixserverlib.ClientEvent `json:"events,omitempty"`
}

type DeviceLists added in v0.10.2

type DeviceLists struct {
	Changed []string `json:"changed,omitempty"`
	Left    []string `json:"left,omitempty"`
}

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              *Summary      `json:"summary,omitempty"`
	State                *ClientEvents `json:"state,omitempty"`
	Timeline             *Timeline     `json:"timeline,omitempty"`
	Ephemeral            *ClientEvents `json:"ephemeral,omitempty"`
	AccountData          *ClientEvents `json:"account_data,omitempty"`
	*UnreadNotifications `json:"unread_notifications,omitempty"`
}

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.

func (JoinResponse) MarshalJSON added in v0.10.2

func (jr JoinResponse) MarshalJSON() ([]byte, error)

type LeaveResponse

type LeaveResponse struct {
	State    *ClientEvents `json:"state,omitempty"`
	Timeline *Timeline     `json:"timeline,omitempty"`
}

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.

func (LeaveResponse) MarshalJSON added in v0.10.2

func (lr LeaveResponse) MarshalJSON() ([]byte, error)

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 RecentEvents added in v0.11.1

type RecentEvents struct {
	Limited bool
	Events  []StreamEvent
}

type RelationEntry added in v0.10.3

type RelationEntry struct {
	Position StreamPosition
	EventID  string
}

type Response

type Response struct {
	NextBatch           StreamingToken    `json:"next_batch"`
	AccountData         *ClientEvents     `json:"account_data,omitempty"`
	Presence            *ClientEvents     `json:"presence,omitempty"`
	Rooms               *RoomsResponse    `json:"rooms,omitempty"`
	ToDevice            *ToDeviceResponse `json:"to_device,omitempty"`
	DeviceLists         *DeviceLists      `json:"device_lists,omitempty"`
	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.

func (Response) MarshalJSON added in v0.10.2

func (r Response) MarshalJSON() ([]byte, error)

type RoomsResponse added in v0.10.2

type RoomsResponse struct {
	Join   map[string]*JoinResponse   `json:"join,omitempty"`
	Peek   map[string]*JoinResponse   `json:"peek,omitempty"`
	Invite map[string]*InviteResponse `json:"invite,omitempty"`
	Leave  map[string]*LeaveResponse  `json:"leave,omitempty"`
}

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
	NewlyJoined bool
	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.

func NewStreamPositionFromString added in v0.10.3

func NewStreamPositionFromString(s string) (StreamPosition, error)

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 Summary added in v0.10.2

type Summary struct {
	Heroes             []string `json:"m.heroes,omitempty"`
	JoinedMemberCount  *int     `json:"m.joined_member_count,omitempty"`
	InvitedMemberCount *int     `json:"m.invited_member_count,omitempty"`
}

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.
	MembershipChanges map[string]struct{}
	// 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 Timeline added in v0.10.2

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

type ToDeviceResponse added in v0.10.2

type ToDeviceResponse struct {
	Events []gomatrixserverlib.SendToDeviceEvent `json:"events,omitempty"`
}

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.

type UnreadNotifications added in v0.10.0

type UnreadNotifications struct {
	HighlightCount    int `json:"highlight_count"`
	NotificationCount int `json:"notification_count"`
}

Jump to

Keyboard shortcuts

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