roomserverapi

package
v0.0.0-...-9835270 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: AGPL-3.0, Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package api provides the types that are used to communicate with the roomserver.

Index

Constants

View Source
const (
	// KindOutlier event fall outside the contiguous event graph.
	// We do not have the state for these events.
	// These events are state events used to authenticate other events.
	// They can become part of the contiguous event graph via backfill.
	KindOutlier = 1
	// KindNew event extend the contiguous graph going forwards.
	// They usually don't need state, but may include state if the
	// there was a new event that references an event that we don't
	// have a copy of.
	KindNew = 2
	// KindBackfill event extend the contiguous graph going backwards.
	// They always have state.
	KindBackfill = 3
)
View Source
const DoNotSendToOtherServers = ""

DoNotSendToOtherServers tells us not to send the event to other matrix servers.

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkEvent

type BulkEvent struct {
	Events  []gomatrixserverlib.Event
	SvrName string
}

type EduApi

type EduApi interface {
	ProcessReceipt(edu *gomatrixserverlib.EDU)
	ProcessTyping(edu *gomatrixserverlib.EDU)
	ProcessProfile(edu *gomatrixserverlib.EDU)
}

type FederationEvent

type FederationEvent struct {
	ReqPath     string
	Destination string
	Reply       string
	RawEvent    RawEvent
	OutputEvent OutputEvent
	RoomState   []byte
	Extra       []byte
}

type GetAliasRoomIDRequest

type GetAliasRoomIDRequest struct {
	// Alias we want to lookup
	Alias string `json:"alias"`
}

GetAliasRoomIDRequest is a request to GetAliasRoomID

type GetAliasRoomIDResponse

type GetAliasRoomIDResponse struct {
	// The room ID the alias refers to
	RoomID string `json:"room_id"`
}

GetAliasRoomIDResponse is a response to GetAliasRoomID

type InputInviteEvent

type InputInviteEvent struct {
	Event gomatrixserverlib.Event `json:"event"`
}

InputInviteEvent is a matrix invite event received over federation without the usual context a matrix room event would have. We usually do not have access to the events needed to check the event auth rules for the invite.

type InputRoomEvent

type InputRoomEvent struct {
	// Whether this event is new, backfilled or an outlier.
	// This controls how the event is processed.
	Kind int `json:"kind"`
	// The event JSON for the event to add.
	Event gomatrixserverlib.Event `json:"event"`
	// The server name to use to push this event to other servers.
	// Or empty if this event shouldn't be pushed to other servers.
	SendAsServer string `json:"send_as_server"`
	// The transaction ID of the send request if sent by a local user and one
	// was specified
	TransactionID *roomservertypes.TransactionID `json:"transaction_id"`
}

InputRoomEvent is a matrix room event to add to the room server database. TODO: Implement UnmarshalJSON/MarshalJSON in a way that does something sensible with the event JSON.

type InputRoomEventsRequest

type InputRoomEventsRequest struct {
	InputRoomEvents   []InputRoomEvent   `json:"input_room_events"`
	InputInviteEvents []InputInviteEvent `json:"input_invite_events"`
}

InputRoomEventsRequest is a request to InputRoomEvents

type InputRoomEventsResponse

type InputRoomEventsResponse struct {
	ErrCode int    `json:"input_room_err_code,omitempty"`
	ErrMsg  string `json:"input_room_err_msg,omitempty"`
	N       int    `json:"n"`
}

InputRoomEventsResponse is a response to InputRoomEvents

type OutputEvent

type OutputEvent struct {
	// What sort of event this is.
	Type OutputType `json:"type"`
	// The content of event with type OutputTypeNewRoomEvent
	NewRoomEvent *OutputNewRoomEvent `json:"new_room_event,omitempty"`
	// The content of event with type OutputTypeNewInviteEvent
	NewInviteEvent *OutputNewInviteEvent `json:"new_invite_event,omitempty"`
	// The content of event with type OutputTypeRetireInviteEvent
	RetireInviteEvent *OutputRetireInviteEvent `json:"retire_invite_event,omitempty"`
}

An OutputEvent is an entry in the roomserver output kafka log. Consumers should check the type field when consuming this event.

type OutputNewInviteEvent

type OutputNewInviteEvent struct {
	// The "m.room.member" invite event.
	Event gomatrixserverlib.ClientEvent `json:"event"`
}

An OutputNewInviteEvent is written whenever an invite becomes active. Invite events can be received outside of an existing room so have to be tracked separately from the room events themselves.

type OutputNewRoomEvent

type OutputNewRoomEvent struct {
	// The Event.
	Event gomatrixserverlib.ClientEvent `json:"event"`
	// The state event IDs that were added to the state of the room by this event.
	// Together with RemovesStateEventIDs this allows the receiver to keep an up to date
	// view of the current state of the room.
	AddsStateEventIDs []string `json:"adds_state_event_ids"`
	// The state event IDs that were removed from the state of the room by this event.
	RemovesStateEventIDs []string `json:"removes_state_event_ids"`
	// The server name to use to push this event to other servers.
	// Or empty if this event shouldn't be pushed to other servers.
	//
	// This is used by the federation sender component. We need to tell it what
	// event it needs to send because it can't tell on its own. Normally if an
	// event was created on this server then we are responsible for sending it.
	// However there are a couple of exceptions. The first is that when the
	// server joins a remote room through another matrix server, it is the job
	// of the other matrix server to send the event over federation. The second
	// is the reverse of the first, that is when a remote server joins a room
	// that we are in over federation using our server it is our responsibility
	// to send the join event to other matrix servers.
	//
	// We encode the server name that the event should be sent using here to
	// future proof the API for virtual hosting.
	SendAsServer string `json:"send_as_server"`
	// The transaction ID of the send request if sent by a local user and one
	// was specified
	TransactionID *roomservertypes.TransactionID `json:"transaction_id"`
	Joined        []string                       `json:"joined"`
}

An OutputNewRoomEvent is written when the roomserver receives a new event. It contains the full matrix room event and enough information for a consumer to construct the current state of the room and the state before the event.

When we talk about state in a matrix room we are talking about the state after a list of events. The current state is the state after the latest event IDs in the room. The state before an event is the state after its prev_events.

type OutputRetireInviteEvent

type OutputRetireInviteEvent struct {
	// The ID of the "m.room.member" invite event.
	EventID string
	// The target user ID of the "m.room.member" invite event that was retired.
	TargetUserID string
	// Optional event ID of the event that replaced the invite.
	// This can be empty if the invite was rejected locally and we were unable
	// to reach the server that originally sent the invite.
	RetiredByEventID string
	// The "membership" of the user after retiring the invite. One of "join"
	// "leave" or "ban".
	Membership string
}

An OutputRetireInviteEvent is written whenever an existing invite is no longer active. An invite stops being active if the user joins the room or if the invite is rejected by the user.

type OutputType

type OutputType string

An OutputType is a type of roomserver output.

const (
	// OutputTypeNewRoomEvent indicates that the event is an OutputNewRoomEvent
	OutputTypeNewRoomEvent OutputType = "new_room_event"
	// OutputTypeNewInviteEvent indicates that the event is an OutputNewInviteEvent
	OutputTypeNewInviteEvent OutputType = "new_invite_event"
	// OutputTypeRetireInviteEvent indicates that the event is an OutputRetireInviteEvent
	OutputTypeRetireInviteEvent OutputType = "retire_invite_event"
	OutputBackfillRoomEvent     OutputType = "back_fill_event"
)

type QueryBackFillEventsRequest

type QueryBackFillEventsRequest gomatrixserverlib.BackfillRequest

type QueryBackFillEventsResponse

type QueryBackFillEventsResponse gomatrixserverlib.BackfillResponse

QueryBackFillEventsResponse is a response to QueryBackFillEventsRequest

type QueryEventAuthRequest

type QueryEventAuthRequest struct {
	EventID string `json:"event_id"`
}

type QueryEventAuthResponse

type QueryEventAuthResponse struct {
	AuthEvents []*gomatrixserverlib.Event
}

type QueryEventsByDomainOffsetRequest

type QueryEventsByDomainOffsetRequest struct {
	RoomID       string `json:"room_id"`
	Domain       string `json:"domain"`
	DomainOffset int64  `json:"domain_offset"`
	EventID      string `json:"event_id"`
	Limit        int    `json:"limit"`
	UseEventID   bool   `json:"use_event_id"`
}

type QueryEventsByDomainOffsetResponse

type QueryEventsByDomainOffsetResponse struct {
	Error string                    `json:"error"`
	PDUs  []gomatrixserverlib.Event `json:"pdus"`
}

type QueryEventsByIDRequest

type QueryEventsByIDRequest struct {
	// The event IDs to look up.
	EventIDs []string `json:"event_ids"`
}

QueryEventsByIDRequest is a request to QueryEventsByID

type QueryEventsByIDResponse

type QueryEventsByIDResponse struct {
	// Copy of the request for debugging.
	EventIDs []string `json:"event_ids"`
	// A list of events with the requested IDs.
	// If the roomserver does not have a copy of a requested event
	// then it will omit that event from the list.
	// If the roomserver thinks it has a copy of the event, but
	// fails to read it from the database then it will fail
	// the entire request.
	// This list will be in an arbitrary order.
	Events []*gomatrixserverlib.Event `json:"events"`
}

QueryEventsByIDResponse is a response to QueryEventsByID

type QueryJoinRoomsRequest

type QueryJoinRoomsRequest struct {
	UserID string `json:"user_id"`
}

type QueryJoinRoomsResponse

type QueryJoinRoomsResponse struct {
	UserID string   `json:"user_id"`
	Rooms  []string `json:"rooms"`
}

type QueryRoomEventByIDRequest

type QueryRoomEventByIDRequest struct {
	EventID string `json:"event_id"`
	RoomID  string `json:"room_id"`
}

QueryRoomEventByIDRequest is a request to QueryEventsByID

type QueryRoomEventByIDResponse

type QueryRoomEventByIDResponse struct {
	// Copy of the request for debugging.
	EventID string                   `json:"event_id"`
	RoomID  string                   `json:"room_id"`
	Event   *gomatrixserverlib.Event `json:"event"`
}

QueryRoomEventByIDResponse is a response to QueryEventsByID

type QueryRoomStateRequest

type QueryRoomStateRequest struct {
	RoomID string `json:"room_id"`
}

type QueryRoomStateResponse

type QueryRoomStateResponse struct {
	RoomID            string                              `json:"room_id"`
	RoomExists        bool                                `json:"room_exists"`
	Creator           *gomatrixserverlib.Event            `json:"create_ev"`
	JoinRule          *gomatrixserverlib.Event            `json:"join_rule_ev"`
	HistoryVisibility *gomatrixserverlib.Event            `json:"history_visibility_ev"`
	Visibility        *gomatrixserverlib.Event            `json:"visibility_ev"`
	Name              *gomatrixserverlib.Event            `json:"name_ev"`
	Topic             *gomatrixserverlib.Event            `json:"topic_ev"`
	Desc              *gomatrixserverlib.Event            `json:"desc_ev"`
	CanonicalAlias    *gomatrixserverlib.Event            `json:"canonical_alias_ev"`
	Power             *gomatrixserverlib.Event            `json:"power_ev"`
	Alias             *gomatrixserverlib.Event            `json:"alias_ev"`
	Join              map[string]*gomatrixserverlib.Event `json:"join_map"`
	Leave             map[string]*gomatrixserverlib.Event `json:"leave_map"`
	Invite            map[string]*gomatrixserverlib.Event `json:"invite_map"`
	ThirdInvite       map[string]*gomatrixserverlib.Event `json:"third_invite_map"`
	Avatar            *gomatrixserverlib.Event            `json:"avatar_ev"`
	GuestAccess       *gomatrixserverlib.Event            `json:"guest_access"`
}

func (*QueryRoomStateResponse) Create

func (*QueryRoomStateResponse) GetAllState

func (rs *QueryRoomStateResponse) GetAllState() []gomatrixserverlib.Event

func (*QueryRoomStateResponse) InitFromEvents

func (rs *QueryRoomStateResponse) InitFromEvents(events []gomatrixserverlib.Event)

func (*QueryRoomStateResponse) JoinRules

func (resp *QueryRoomStateResponse) JoinRules() (*gomatrixserverlib.Event, error)

func (*QueryRoomStateResponse) Member

func (resp *QueryRoomStateResponse) Member(stateKey string) (*gomatrixserverlib.Event, error)

func (*QueryRoomStateResponse) PowerLevels

func (resp *QueryRoomStateResponse) PowerLevels() (*gomatrixserverlib.Event, error)

func (*QueryRoomStateResponse) RoomAvatar

func (resp *QueryRoomStateResponse) RoomAvatar() (*gomatrixserverlib.Event, error)

func (*QueryRoomStateResponse) RoomName

func (resp *QueryRoomStateResponse) RoomName() (*gomatrixserverlib.Event, error)

func (*QueryRoomStateResponse) ThirdPartyInvite

func (resp *QueryRoomStateResponse) ThirdPartyInvite(stateKey string) (*gomatrixserverlib.Event, error)

type RawEvent

type RawEvent struct {
	RoomID     string
	Kind       int
	Trust      bool
	Reply      string
	TxnID      *roomservertypes.TransactionID
	BulkEvents BulkEvent
	Query      []string
}

type RemoveRoomAliasRequest

type RemoveRoomAliasRequest struct {
	// ID of the user removing the alias
	UserID string `json:"user_id"`
	// The room alias to remove
	Alias string `json:"alias"`
}

RemoveRoomAliasRequest is a request to RemoveRoomAlias

type RemoveRoomAliasResponse

type RemoveRoomAliasResponse struct{}

RemoveRoomAliasResponse is a response to RemoveRoomAlias

type RoomserverAliasAPI

type RoomserverAliasAPI interface {
	AllocRoomAlias(
		ctx context.Context,
		req *SetRoomAliasRequest,
		response *SetRoomAliasResponse,
	) error

	// Set a room alias
	SetRoomAlias(
		ctx context.Context,
		req *SetRoomAliasRequest,
		response *SetRoomAliasResponse,
	) error

	// Get the room ID for an alias
	GetAliasRoomID(
		ctx context.Context,
		req *GetAliasRoomIDRequest,
		response *GetAliasRoomIDResponse,
	) error

	// Remove a room alias
	RemoveRoomAlias(
		ctx context.Context,
		req *RemoveRoomAliasRequest,
		response *RemoveRoomAliasResponse,
	) error
}

RoomserverAliasAPI is used to save, lookup or remove a room alias

type RoomserverAliasRequest

type RoomserverAliasRequest struct {
	SetRoomAliasRequest    *SetRoomAliasRequest    `json:"set_room_alias,omitempty"`
	GetAliasRoomIDRequest  *GetAliasRoomIDRequest  `json:"get_room_alias,omitempty"`
	RemoveRoomAliasRequest *RemoveRoomAliasRequest `json:"rem_room_alias,omitempty"`
	AllocRoomAliasRequest  *SetRoomAliasRequest    `json:"alloc_room_alias,omitempty"`
	Reply                  string
}

type RoomserverInputAPI

type RoomserverInputAPI interface {
	InputRoomEvents(
		ctx context.Context,
		input *RawEvent,
	) (int, error)
}

RoomserverInputAPI is used to write events to the room server.

type RoomserverQueryAPI

type RoomserverQueryAPI interface {
	// Query a list of events by event ID.
	QueryEventsByID(
		ctx context.Context,
		request *QueryEventsByIDRequest,
		response *QueryEventsByIDResponse,
	) error

	QueryRoomEventByID(
		ctx context.Context,
		request *QueryRoomEventByIDRequest,
		response *QueryRoomEventByIDResponse,
	) error

	QueryJoinRooms(
		ctx context.Context,
		request *QueryJoinRoomsRequest,
		response *QueryJoinRoomsResponse,
	) error

	QueryRoomState(
		ctx context.Context,
		request *QueryRoomStateRequest,
		response *QueryRoomStateResponse,
	) error

	QueryBackFillEvents(
		ctx context.Context,
		request *QueryBackFillEventsRequest,
		response *QueryBackFillEventsResponse,
	) error

	QueryEventAuth(
		ctx context.Context,
		request *QueryEventAuthRequest,
		response *QueryEventAuthResponse,
	) error

	QueryEventsByDomainOffset(
		ctx context.Context,
		request *QueryEventsByDomainOffsetRequest,
		response *QueryEventsByDomainOffsetResponse,
	) error
}

RoomserverQueryAPI is used to query information from the room server.

type RoomserverRPCAPI

type RoomserverRPCAPI interface {
	RoomserverAliasAPI
	RoomserverQueryAPI
	EduApi

	InputRoomEvents(context.Context, *RawEvent) (int, error)
}

type RoomserverRpcRequest

type RoomserverRpcRequest struct {
	QueryEventsByID           *QueryEventsByIDRequest           `json:"qry_events_by_id,omitempty"`
	QueryRoomEventByID        *QueryRoomEventByIDRequest        `json:"qry_room_events_by_id,omitempty"`
	QueryJoinRooms            *QueryJoinRoomsRequest            `json:"qry_join_rooms,omitempty"`
	QueryRoomState            *QueryRoomStateRequest            `json:"qry_room_state,omitempty"`
	QueryBackFillEvents       *QueryBackFillEventsRequest       `json:"qry_back_fill,omitempty"`
	QueryEventAuth            *QueryEventAuthRequest            `json:"qry_event_auth,omitempty"`
	QueryEventsByDomainOffset *QueryEventsByDomainOffsetRequest `json:"qry_events_by_domain_offset,omitempty"`
	Reply                     string
}

type SetRoomAliasRequest

type SetRoomAliasRequest struct {
	// ID of the user setting the alias
	UserID string `json:"user_id"`
	// New alias for the room
	Alias string `json:"alias"`
	// The room ID the alias is referring to
	RoomID string `json:"room_id"`
}

SetRoomAliasRequest is a request to SetRoomAlias

type SetRoomAliasResponse

type SetRoomAliasResponse struct {
	// Does the alias already refer to a room?
	AliasExists bool `json:"alias_exists"`
}

SetRoomAliasResponse is a response to SetRoomAlias

Jump to

Keyboard shortcuts

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