gomatrix

package module
v0.0.0-...-de42b31 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

README

Documentation

Overview

Package gomatrix implements the Matrix Client-Server API.

Specification can be found at http://matrix.org/docs/spec/client_server/r0.2.0.html

Example (CustomInterfaces)
// Custom interfaces must be set prior to calling functions on the client.
cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "MDAefhiuwehfuiwe")

// anything which implements the Storer interface
customStore := NewInMemoryStore()
cli.Store = customStore

// anything which implements the Syncer interface
customSyncer := NewDefaultSyncer("@example:matrix.org", customStore)
cli.Syncer = customSyncer

// any http.Client
cli.Client = http.DefaultClient

// Once you call a function, you can't safely change the interfaces.
cli.SendText("!foo:bar", "Down the rabbit hole")
Output:

Example (Sync)
cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "MDAefhiuwehfuiwe")
cli.Store.SaveFilterID("@example:matrix.org", "2")                // Optional: if you know it already
cli.Store.SaveNextBatch("@example:matrix.org", "111_222_333_444") // Optional: if you know it already
syncer := cli.Syncer.(*DefaultSyncer)
syncer.OnEventType("m.room.message", func(ev *Event) {
	fmt.Println("Message: ", ev)
})

// Blocking version
if err := cli.Sync(); err != nil {
	fmt.Println("Sync() returned ", err)
}

// Non-blocking version
go func() {
	for {
		if err := cli.Sync(); err != nil {
			fmt.Println("Sync() returned ", err)
		}
		// Optional: Wait a period of time before trying to sync again.
	}
}()
Output:

Index

Examples

Constants

View Source
const (
	MsgText     MessageType = "m.text"
	MsgEmote                = "m.emote"
	MsgNotice               = "m.notice"
	MsgImage                = "m.image"
	MsgLocation             = "m.location"
	MsgVideo                = "m.video"
	MsgAudio                = "m.audio"
	MsgFile                 = "m.file"
)

Msgtypes

View Source
const ReplyFormat = `` /* 143-byte string literal not displayed */

Variables

View Source
var (
	StateAliases        = EventType{"m.room.aliases", StateEventType}
	StateCanonicalAlias = EventType{"m.room.canonical_alias", StateEventType}
	StateCreate         = EventType{"m.room.create", StateEventType}
	StateJoinRules      = EventType{"m.room.join_rules", StateEventType}
	StateMember         = EventType{"m.room.member", StateEventType}
	StatePowerLevels    = EventType{"m.room.power_levels", StateEventType}
	StateRoomName       = EventType{"m.room.name", StateEventType}
	StateTopic          = EventType{"m.room.topic", StateEventType}
	StateRoomAvatar     = EventType{"m.room.avatar", StateEventType}
	StatePinnedEvents   = EventType{"m.room.pinned_events", StateEventType}
)

State events

View Source
var (
	EventRedaction = EventType{"m.room.redaction", MessageEventType}
	EventMessage   = EventType{"m.room.message", MessageEventType}
	EventSticker   = EventType{"m.sticker", MessageEventType}
)

Message events

View Source
var (
	EphemeralEventReceipt = EventType{"m.receipt", EphemeralEventType}
	EphemeralEventTyping  = EventType{"m.typing", EphemeralEventType}
)

Ephemeral events

View Source
var (
	AccountDataDirectChats = EventType{"m.direct", AccountDataEventType}
	AccountDataPushRules   = EventType{"m.push_rules", AccountDataEventType}
	AccountDataRoomTags    = EventType{"m.tag", AccountDataEventType}
)

Account data events

View Source
var DisableFancyEventParsing = false
View Source
var HTMLReplyFallbackRegex = regexp.MustCompile(`^<mx-reply>[\s\S]+?</mx-reply>`)

Functions

func DecodeUserLocalpart

func DecodeUserLocalpart(str string) (string, error)

DecodeUserLocalpart decodes the given string back into the original input string. Returns an error if the given string is not a valid user ID localpart encoding. See http://matrix.org/docs/spec/intro.html#mapping-from-other-character-sets

This decodes quoted-printable bytes back into UTF8, and unescapes casing. For example:

_alph=40_bet=5f50up  =>  Alph@Bet_50up

Returns an error if the input string contains characters outside the range "a-z0-9._=-", has an invalid quote-printable byte (e.g. not hex), or has an invalid _ escaped byte (e.g. "_5").

Example
localpart, err := DecodeUserLocalpart("_alph=40_bet__50up")
if err != nil {
	panic(err)
}
fmt.Println(localpart)
Output:

Alph@Bet_50up

func EncodeUserLocalpart

func EncodeUserLocalpart(str string) string

EncodeUserLocalpart encodes the given string into Matrix-compliant user ID localpart form. See http://matrix.org/docs/spec/intro.html#mapping-from-other-character-sets

This returns a string with only the characters "a-z0-9._=-". The uppercase range A-Z are encoded using leading underscores ("_"). Characters outside the aforementioned ranges (including literal underscores ("_") and equals ("=")) are encoded as UTF8 code points (NOT NCRs) and converted to lower-case hex with a leading "=". For example:

Alph@Bet_50up  => _alph=40_bet=5f50up
Example
localpart := EncodeUserLocalpart("Alph@Bet_50up")
fmt.Println(localpart)
Output:

_alph=40_bet__50up

func ExtractUserLocalpart

func ExtractUserLocalpart(userID string) (string, error)

ExtractUserLocalpart extracts the localpart portion of a user ID. See http://matrix.org/docs/spec/intro.html#user-identifiers

Example
localpart, err := ExtractUserLocalpart("@alice:matrix.org")
if err != nil {
	panic(err)
}
fmt.Println(localpart)
Output:

alice

func TrimReplyFallbackHTML

func TrimReplyFallbackHTML(html string) string

func TrimReplyFallbackText

func TrimReplyFallbackText(text string) string

Types

type CanonicalAlias

type CanonicalAlias struct {
	Alias string `json:"alias,omitempty"`
}

type Client

type Client struct {
	HomeserverURL *url.URL     // The base homeserver URL
	Prefix        string       // The API prefix eg '/_matrix/client/r0'
	UserID        string       // The user ID of the client. Used for forming HTTP paths which use the client's user ID.
	AccessToken   string       // The access_token for the client.
	Client        *http.Client // The underlying HTTP client which will be used to make HTTP requests.
	Syncer        Syncer       // The thing which can process /sync responses
	Store         Storer       // The thing which can store rooms/tokens/ids
	Logger        maulogger.Logger

	// The ?user_id= query parameter for application services. This must be set *prior* to calling a method. If this is empty,
	// no user_id parameter will be sent.
	// See http://matrix.org/docs/spec/application_service/unstable.html#identity-assertion
	AppServiceUserID string
	// contains filtered or unexported fields
}

Client represents a Matrix client.

func NewClient

func NewClient(homeserverURL, userID, accessToken string) (*Client, error)

NewClient creates a new Matrix Client ready for syncing

func (*Client) BanUser

func (cli *Client) BanUser(roomID string, req *ReqBanUser) (resp *RespBanUser, err error)

BanUser bans a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban

func (*Client) BuildBaseURL

func (cli *Client) BuildBaseURL(urlPath ...string) string

BuildBaseURL builds a URL with the Client's homeserver/access_token set already. You must supply the prefix in the path.

Example
userID := "@example:matrix.org"
cli, _ := NewClient("https://matrix.org", userID, "abcdef123456")
out := cli.BuildBaseURL("_matrix", "client", "r0", "directory", "room", "#matrix:matrix.org")
fmt.Println(out)
Output:

https://matrix.org/_matrix/client/r0/directory/room/%23matrix:matrix.org?access_token=abcdef123456

func (*Client) BuildURL

func (cli *Client) BuildURL(urlPath ...string) string

BuildURL builds a URL with the Client's homserver/prefix/access_token set already.

Example
userID := "@example:matrix.org"
cli, _ := NewClient("https://matrix.org", userID, "abcdef123456")
out := cli.BuildURL("user", userID, "filter")
fmt.Println(out)
Output:

https://matrix.org/_matrix/client/r0/user/@example:matrix.org/filter?access_token=abcdef123456

func (*Client) BuildURLWithQuery

func (cli *Client) BuildURLWithQuery(urlPath []string, urlQuery map[string]string) string

BuildURLWithQuery builds a URL with query parameters in addition to the Client's homeserver/prefix/access_token set already.

Example
cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "abcdef123456")
out := cli.BuildURLWithQuery([]string{"sync"}, map[string]string{
	"filter_id": "5",
})
fmt.Println(out)
Output:

https://matrix.org/_matrix/client/r0/sync?access_token=abcdef123456&filter_id=5

func (*Client) ClearCredentials

func (cli *Client) ClearCredentials()

ClearCredentials removes the user ID and access token on this client instance.

func (*Client) CreateFilter

func (cli *Client) CreateFilter(filter json.RawMessage) (resp *RespCreateFilter, err error)

CreateFilter makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter

func (*Client) CreateRoom

func (cli *Client) CreateRoom(req *ReqCreateRoom) (resp *RespCreateRoom, err error)

CreateRoom creates a new Matrix room. See https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom

resp, err := cli.CreateRoom(&gomatrix.ReqCreateRoom{
	Preset: "public_chat",
})
fmt.Println("Room:", resp.RoomID)

func (*Client) Download

func (cli *Client) Download(mxcURL string) (io.ReadCloser, error)

func (*Client) DownloadBytes

func (cli *Client) DownloadBytes(mxcURL string) ([]byte, error)

func (*Client) ForgetRoom

func (cli *Client) ForgetRoom(roomID string) (resp *RespForgetRoom, err error)

ForgetRoom forgets a room entirely. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget

func (*Client) GetAvatarURL

func (cli *Client) GetAvatarURL() (url string, err error)

GetAvatarURL gets the user's avatar URL. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url

func (*Client) GetDisplayName

func (cli *Client) GetDisplayName(mxid string) (resp *RespUserDisplayName, err error)

GetDisplayName returns the display name of the user from the specified MXID. See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname

func (*Client) GetEvent

func (cli *Client) GetEvent(roomID, eventID string) (resp *Event, err error)

func (*Client) GetOwnDisplayName

func (cli *Client) GetOwnDisplayName() (resp *RespUserDisplayName, err error)

GetOwnDisplayName returns the user's display name. See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname

func (*Client) InviteUser

func (cli *Client) InviteUser(roomID string, req *ReqInviteUser) (resp *RespInviteUser, err error)

InviteUser invites a user to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite

func (*Client) InviteUserByThirdParty

func (cli *Client) InviteUserByThirdParty(roomID string, req *ReqInvite3PID) (resp *RespInviteUser, err error)

InviteUserByThirdParty invites a third-party identifier to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#invite-by-third-party-id-endpoint

func (*Client) JoinRoom

func (cli *Client) JoinRoom(roomIDorAlias, serverName string, content interface{}) (resp *RespJoinRoom, err error)

JoinRoom joins the client to a room ID or alias. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias

If serverName is specified, this will be added as a query param to instruct the homeserver to join via that server. If content is specified, it will be JSON encoded and used as the request body.

Example (Alias)

Join a room by alias.

cli, _ := NewClient("http://localhost:8008", "@example:localhost", "abcdef123456")
if resp, err := cli.JoinRoom("#test:localhost", "", nil); err != nil {
	panic(err)
} else {
	// Use room ID for something.
	_ = resp.RoomID
}
Output:

Example (Id)

Join a room by ID.

cli, _ := NewClient("http://localhost:8008", "@example:localhost", "abcdef123456")
if _, err := cli.JoinRoom("!uOILRrqxnsYgQdUzar:localhost", "", nil); err != nil {
	panic(err)
}
Output:

func (*Client) JoinedMembers

func (cli *Client) JoinedMembers(roomID string) (resp *RespJoinedMembers, err error)

JoinedMembers returns a map of joined room members. See TODO-SPEC. https://github.com/matrix-org/synapse/pull/1680

In general, usage of this API is discouraged in favour of /sync, as calling this API can race with incoming membership changes. This API is primarily designed for application services which may want to efficiently look up joined members in a room.

func (*Client) JoinedRooms

func (cli *Client) JoinedRooms() (resp *RespJoinedRooms, err error)

JoinedRooms returns a list of rooms which the client is joined to. See TODO-SPEC. https://github.com/matrix-org/synapse/pull/1680

In general, usage of this API is discouraged in favour of /sync, as calling this API can race with incoming membership changes. This API is primarily designed for application services which may want to efficiently look up joined rooms.

func (*Client) KickUser

func (cli *Client) KickUser(roomID string, req *ReqKickUser) (resp *RespKickUser, err error)

KickUser kicks a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick

func (*Client) LeaveRoom

func (cli *Client) LeaveRoom(roomID string) (resp *RespLeaveRoom, err error)

LeaveRoom leaves the given room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave

func (*Client) LogRequest

func (cli *Client) LogRequest(req *http.Request, body string)

func (*Client) Login

func (cli *Client) Login(req *ReqLogin) (resp *RespLogin, err error)

Login a user to the homeserver according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login This does not set credentials on this client instance. See SetCredentials() instead.

Example

Login to a local homeserver and set the user ID and access token on success.

cli, _ := NewClient("http://localhost:8008", "", "")
resp, err := cli.Login(&ReqLogin{
	Type:     "m.login.password",
	User:     "alice",
	Password: "wonderland",
})
if err != nil {
	panic(err)
}
cli.SetCredentials(resp.UserID, resp.AccessToken)
Output:

func (*Client) Logout

func (cli *Client) Logout() (resp *RespLogout, err error)

Logout the current user. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout This does not clear the credentials from the client instance. See ClearCredentials() instead.

func (*Client) MakeRequest

func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{}, resBody interface{}) ([]byte, error)

MakeRequest makes a JSON HTTP request to the given URL. If "resBody" is not nil, the response body will be json.Unmarshalled into it.

Returns the HTTP body as bytes on 2xx with a nil error. Returns an error if the response is not 2xx along with the HTTP body bytes if it got that far. This error is an HTTPError which includes the returned HTTP status code and possibly a RespError as the WrappedError, if the HTTP body could be decoded as a RespError.

func (*Client) MarkRead

func (cli *Client) MarkRead(roomID, eventID string) (err error)

func (*Client) Messages

func (cli *Client) Messages(roomID, from, to string, dir rune, limit int) (resp *RespMessages, err error)

Messages returns a list of message and state events for a room. It uses pagination query parameters to paginate history in the room. See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages

func (*Client) RedactEvent

func (cli *Client) RedactEvent(roomID, eventID string, req *ReqRedact) (resp *RespSendEvent, err error)

RedactEvent redacts the given event. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid

func (*Client) Register

func (cli *Client) Register(req *ReqRegister) (*RespRegister, *RespUserInteractive, error)

Register makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register

Registers with kind=user. For kind=guest, see RegisterGuest.

func (*Client) RegisterDummy

func (cli *Client) RegisterDummy(req *ReqRegister) (*RespRegister, error)

RegisterDummy performs m.login.dummy registration according to https://matrix.org/docs/spec/client_server/r0.2.0.html#dummy-auth

Only a username and password need to be provided on the ReqRegister struct. Most local/developer homeservers will allow registration this way. If the homeserver does not, an error is returned.

This does not set credentials on the client instance. See SetCredentials() instead.

	res, err := cli.RegisterDummy(&gomatrix.ReqRegister{
		Username: "alice",
		Password: "wonderland",
	})
 if err != nil {
		panic(err)
	}
	token := res.AccessToken

func (*Client) RegisterGuest

func (cli *Client) RegisterGuest(req *ReqRegister) (*RespRegister, *RespUserInteractive, error)

RegisterGuest makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register with kind=guest.

For kind=user, see Register.

func (*Client) SendImage

func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error)

SendImage sends an m.room.message event into the given room with a msgtype of m.image See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image

func (*Client) SendMassagedMessageEvent

func (cli *Client) SendMassagedMessageEvent(roomID string, eventType EventType, contentJSON interface{}, ts int64) (resp *RespSendEvent, err error)

SendMessageEvent sends a message event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.

func (*Client) SendMassagedStateEvent

func (cli *Client) SendMassagedStateEvent(roomID string, eventType EventType, stateKey string, contentJSON interface{}, ts int64) (resp *RespSendEvent, err error)

SendStateEvent sends a state event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.

func (*Client) SendMessageEvent

func (cli *Client) SendMessageEvent(roomID string, eventType EventType, contentJSON interface{}) (resp *RespSendEvent, err error)

SendMessageEvent sends a message event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.

func (*Client) SendNotice

func (cli *Client) SendNotice(roomID, text string) (*RespSendEvent, error)

SendNotice sends an m.room.message event into the given room with a msgtype of m.notice See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-notice

func (*Client) SendStateEvent

func (cli *Client) SendStateEvent(roomID string, eventType EventType, stateKey string, contentJSON interface{}) (resp *RespSendEvent, err error)

SendStateEvent sends a state event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.

func (*Client) SendText

func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error)

SendText sends an m.room.message event into the given room with a msgtype of m.text See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-text

func (*Client) SendVideo

func (cli *Client) SendVideo(roomID, body, url string) (*RespSendEvent, error)

SendVideo sends an m.room.message event into the given room with a msgtype of m.video See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-video

func (*Client) SetAvatarURL

func (cli *Client) SetAvatarURL(url string) (err error)

SetAvatarURL sets the user's avatar URL. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url

func (*Client) SetCredentials

func (cli *Client) SetCredentials(userID, accessToken string)

SetCredentials sets the user ID and access token on this client instance.

func (*Client) SetDisplayName

func (cli *Client) SetDisplayName(displayName string) (err error)

SetDisplayName sets the user's profile display name. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname

func (*Client) SetPresence

func (cli *Client) SetPresence(status string) (err error)

func (*Client) StateEvent

func (cli *Client) StateEvent(roomID string, eventType EventType, stateKey string, outContent interface{}) (err error)

StateEvent gets a single state event in a room. It will attempt to JSON unmarshal into the given "outContent" struct with the HTTP response body, or return an error. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-statekey

Example

Retrieve the content of a m.room.name state event.

content := struct {
	Name string `json:"name"`
}{}
cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "abcdef123456")
if err := cli.StateEvent("!foo:bar", "m.room.name", "", &content); err != nil {
	panic(err)
}
Output:

func (*Client) StopSync

func (cli *Client) StopSync()

StopSync stops the ongoing sync started by Sync.

func (*Client) Sync

func (cli *Client) Sync() error

Sync starts syncing with the provided Homeserver. If Sync() is called twice then the first sync will be stopped and the error will be nil.

This function will block until a fatal /sync error occurs, so it should almost always be started as a new goroutine. Fatal sync errors can be caused by:

  • The failure to create a filter.
  • Client.Syncer.OnFailedSync returning an error in response to a failed sync.
  • Client.Syncer.ProcessResponse returning an error.

If you wish to continue retrying in spite of these fatal errors, call Sync() again.

func (*Client) SyncRequest

func (cli *Client) SyncRequest(timeout int, since, filterID string, fullState bool, setPresence string) (resp *RespSync, err error)

SyncRequest makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync

func (*Client) TurnServer

func (cli *Client) TurnServer() (resp *RespTurnServer, err error)

TurnServer returns turn server details and credentials for the client to use when initiating calls. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver

func (*Client) UnbanUser

func (cli *Client) UnbanUser(roomID string, req *ReqUnbanUser) (resp *RespUnbanUser, err error)

UnbanUser unbans a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban

func (*Client) Upload

func (cli *Client) Upload(content io.Reader, contentType string, contentLength int64) (*RespMediaUpload, error)

UploadToContentRepo uploads the given bytes to the content repository and returns an MXC URI. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload

func (*Client) UploadBytes

func (cli *Client) UploadBytes(data []byte, contentType string) (*RespMediaUpload, error)
func (cli *Client) UploadLink(link string) (*RespMediaUpload, error)

UploadLink uploads an HTTP URL and then returns an MXC URI.

func (*Client) UserTyping

func (cli *Client) UserTyping(roomID string, typing bool, timeout int64) (resp *RespTyping, err error)

UserTyping sets the typing status of the user. See https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid

func (*Client) Versions

func (cli *Client) Versions() (resp *RespVersions, err error)

Versions returns the list of supported Matrix versions on this homeserver. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions

type Content

type Content struct {
	VeryRaw json.RawMessage        `json:"-"`
	Raw     map[string]interface{} `json:"-"`

	MsgType       MessageType `json:"msgtype,omitempty"`
	Body          string      `json:"body,omitempty"`
	Format        Format      `json:"format,omitempty"`
	FormattedBody string      `json:"formatted_body,omitempty"`

	Info *FileInfo `json:"info,omitempty"`
	URL  string    `json:"url,omitempty"`

	// Membership key for easy access in m.room.member events
	Membership Membership `json:"membership,omitempty"`

	RelatesTo *RelatesTo      `json:"m.relates_to,omitempty"`
	Command   *MatchedCommand `json:"m.command,omitempty"`

	PowerLevels
	Member
	Aliases []string `json:"aliases,omitempty"`
	CanonicalAlias
	RoomName
	RoomTopic

	RoomTags      Tags     `json:"tags,omitempty"`
	TypingUserIDs []string `json:"user_ids,omitempty"`
}

func (*Content) GetCommand

func (content *Content) GetCommand() *MatchedCommand

func (*Content) GetInfo

func (content *Content) GetInfo() *FileInfo

func (*Content) GetRelatesTo

func (content *Content) GetRelatesTo() *RelatesTo

func (*Content) GetReplyTo

func (content *Content) GetReplyTo() string

func (*Content) RemoveReplyFallback

func (content *Content) RemoveReplyFallback()

func (*Content) SetReply

func (content *Content) SetReply(inReplyTo *Event)

func (*Content) UnmarshalCanonicalAlias

func (content *Content) UnmarshalCanonicalAlias() (ca CanonicalAlias, err error)

func (*Content) UnmarshalJSON

func (content *Content) UnmarshalJSON(data []byte) error

func (*Content) UnmarshalMember

func (content *Content) UnmarshalMember() (m Member, err error)

func (*Content) UnmarshalPowerLevels

func (content *Content) UnmarshalPowerLevels() (pl PowerLevels, err error)

type DefaultSyncer

type DefaultSyncer struct {
	UserID string
	Store  Storer
	// contains filtered or unexported fields
}

DefaultSyncer is the default syncing implementation. You can either write your own syncer, or selectively replace parts of this default syncer (e.g. the ProcessResponse method). The default syncer uses the observer pattern to notify callers about incoming events. See DefaultSyncer.OnEventType for more information.

func NewDefaultSyncer

func NewDefaultSyncer(userID string, store Storer) *DefaultSyncer

NewDefaultSyncer returns an instantiated DefaultSyncer

func (*DefaultSyncer) GetFilterJSON

func (s *DefaultSyncer) GetFilterJSON(userID string) json.RawMessage

GetFilterJSON returns a filter with a timeline limit of 50.

func (*DefaultSyncer) OnEventType

func (s *DefaultSyncer) OnEventType(eventType EventType, callback OnEventListener)

OnEventType allows callers to be notified when there are new events for the given event type. There are no duplicate checks.

func (*DefaultSyncer) OnFailedSync

func (s *DefaultSyncer) OnFailedSync(res *RespSync, err error) (time.Duration, error)

OnFailedSync always returns a 10 second wait period between failed /syncs, never a fatal error.

func (*DefaultSyncer) ProcessResponse

func (s *DefaultSyncer) ProcessResponse(res *RespSync, since string) (err error)

ProcessResponse processes the /sync response in a way suitable for bots. "Suitable for bots" means a stream of unrepeating events. Returns a fatal error if a listener panics.

type Event

type Event struct {
	StateKey  *string   `json:"state_key,omitempty"` // The state key for the event. Only present on State Events.
	Sender    string    `json:"sender"`              // The user ID of the sender of the event
	Type      EventType `json:"type"`                // The event type
	Timestamp int64     `json:"origin_server_ts"`    // The unix timestamp when this message was sent by the origin server
	ID        string    `json:"event_id"`            // The unique ID of this event
	RoomID    string    `json:"room_id"`             // The room the event was sent to. May be nil (e.g. for presence)
	Content   Content   `json:"content"`             // The JSON content of the event.
	Redacts   string    `json:"redacts,omitempty"`   // The event ID that was redacted if a m.room.redaction event
	Unsigned  Unsigned  `json:"unsigned,omitempty"`  // Unsigned content set by own homeserver.

	InviteRoomState []StrippedState `json:"invite_room_state"`
}

Event represents a single Matrix event.

func (*Event) GenerateReplyFallbackHTML

func (evt *Event) GenerateReplyFallbackHTML() string

func (*Event) GenerateReplyFallbackText

func (evt *Event) GenerateReplyFallbackText() string

func (*Event) GetStateKey

func (evt *Event) GetStateKey() string

type EventType

type EventType struct {
	Type  string
	Class EventTypeClass
}

func NewEventType

func NewEventType(name string) EventType

func (*EventType) GuessClass

func (et *EventType) GuessClass() EventTypeClass

func (*EventType) IsCustom

func (et *EventType) IsCustom() bool

func (*EventType) IsEphemeral

func (et *EventType) IsEphemeral() bool

func (*EventType) IsState

func (et *EventType) IsState() bool

func (*EventType) MarshalJSON

func (et *EventType) MarshalJSON() ([]byte, error)

func (*EventType) String

func (et *EventType) String() string

func (*EventType) UnmarshalJSON

func (et *EventType) UnmarshalJSON(data []byte) error

type EventTypeClass

type EventTypeClass int
const (
	// Normal message events
	MessageEventType EventTypeClass = iota
	// State events
	StateEventType
	// Ephemeral events
	EphemeralEventType
	// Account data events
	AccountDataEventType
	// Unknown events
	UnknownEventType
)

type FileInfo

type FileInfo struct {
	MimeType      string    `json:"mimetype,omitempty"`
	ThumbnailInfo *FileInfo `json:"thumbnail_info,omitempty"`
	ThumbnailURL  string    `json:"thumbnail_url,omitempty"`
	Height        int       `json:"h,omitempty"`
	Width         int       `json:"w,omitempty"`
	Duration      uint      `json:"duration,omitempty"`
	Size          int       `json:"size,omitempty"`
}

func (*FileInfo) GetThumbnailInfo

func (fileInfo *FileInfo) GetThumbnailInfo() *FileInfo

type Filter

type Filter struct {
	AccountData FilterPart `json:"account_data,omitempty"`
	EventFields []string   `json:"event_fields,omitempty"`
	EventFormat string     `json:"event_format,omitempty"`
	Presence    FilterPart `json:"presence,omitempty"`
	Room        RoomFilter `json:"room,omitempty"`
}

Filter is used by clients to specify how the server should filter responses to e.g. sync requests Specified by: https://matrix.org/docs/spec/client_server/r0.2.0.html#filtering

func DefaultFilter

func DefaultFilter() Filter

DefaultFilter returns the default filter used by the Matrix server if no filter is provided in the request

func (*Filter) Validate

func (filter *Filter) Validate() error

Validate checks if the filter contains valid property values

type FilterPart

type FilterPart struct {
	NotRooms    []string `json:"not_rooms,omitempty"`
	Rooms       []string `json:"rooms,omitempty"`
	Limit       int      `json:"limit,omitempty"`
	NotSenders  []string `json:"not_senders,omitempty"`
	NotTypes    []string `json:"not_types,omitempty"`
	Senders     []string `json:"senders,omitempty"`
	Types       []string `json:"types,omitempty"`
	ContainsURL *bool    `json:"contains_url,omitempty"`
}

FilterPart is used to define filtering rules for specific categories of events

func DefaultFilterPart

func DefaultFilterPart() FilterPart

DefaultFilterPart returns the default filter part used by the Matrix server if no filter is provided in the request

type Format

type Format string
const (
	FormatHTML Format = "org.matrix.custom.html"
)

Message formats

type HTTPError

type HTTPError struct {
	WrappedError error
	RespError    *RespError
	Message      string
	Code         int
}

HTTPError An HTTP Error response, which may wrap an underlying native Go Error.

func (HTTPError) Error

func (e HTTPError) Error() string

type InMemoryStore

type InMemoryStore struct {
	Filters   map[string]string
	NextBatch map[string]string
	Rooms     map[string]*Room
}

InMemoryStore implements the Storer interface.

Everything is persisted in-memory as maps. It is not safe to load/save filter IDs or next batch tokens on any goroutine other than the syncing goroutine: the one which called Client.Sync().

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore constructs a new InMemoryStore.

func (*InMemoryStore) LoadFilterID

func (s *InMemoryStore) LoadFilterID(userID string) string

LoadFilterID from memory.

func (*InMemoryStore) LoadNextBatch

func (s *InMemoryStore) LoadNextBatch(userID string) string

LoadNextBatch from memory.

func (*InMemoryStore) LoadRoom

func (s *InMemoryStore) LoadRoom(roomID string) *Room

LoadRoom from memory.

func (*InMemoryStore) SaveFilterID

func (s *InMemoryStore) SaveFilterID(userID, filterID string)

SaveFilterID to memory.

func (*InMemoryStore) SaveNextBatch

func (s *InMemoryStore) SaveNextBatch(userID, nextBatchToken string)

SaveNextBatch to memory.

func (*InMemoryStore) SaveRoom

func (s *InMemoryStore) SaveRoom(room *Room)

SaveRoom to memory.

type InReplyTo

type InReplyTo struct {
	EventID string `json:"event_id,omitempty"`
	// Not required, just for future-proofing
	RoomID string `json:"room_id,omitempty"`
}

type MatchedCommand

type MatchedCommand struct {
	Target    string            `json:"target"`
	Matched   string            `json:"matched"`
	Arguments map[string]string `json:"arguments"`
}

type MatchedPassiveCommand

type MatchedPassiveCommand struct {
	// Matched  string     `json:"matched"`
	// Value    string     `json:"value"`
	Captured [][]string `json:"captured"`

	BackCompatCommand   string            `json:"command"`
	BackCompatArguments map[string]string `json:"arguments"`
}

type Member

type Member struct {
	Membership       Membership        `json:"membership,omitempty"`
	AvatarURL        string            `json:"avatar_url,omitempty"`
	Displayname      string            `json:"displayname,omitempty"`
	ThirdPartyInvite *ThirdPartyInvite `json:"third_party_invite,omitempty"`
	Reason           string            `json:"reason,omitempty"`
}

type Membership

type Membership string

Membership is an enum specifying the membership state of a room member.

const (
	MembershipJoin   Membership = "join"
	MembershipLeave  Membership = "leave"
	MembershipInvite Membership = "invite"
	MembershipBan    Membership = "ban"
	MembershipKnock  Membership = "knock"
)

The allowed membership states as specified in spec section 10.5.5.

type MessageType

type MessageType string

type OnEventListener

type OnEventListener func(*Event)

OnEventListener can be used with DefaultSyncer.OnEventType to be informed of incoming events.

type PowerLevels

type PowerLevels struct {
	Users        map[string]int `json:"users,omitempty"`
	UsersDefault int            `json:"users_default,omitempty"`

	Events        map[string]int `json:"events,omitempty"`
	EventsDefault int            `json:"events_default,omitempty"`

	StateDefaultPtr *int `json:"state_default,omitempty"`

	InvitePtr *int `json:"invite,omitempty"`
	KickPtr   *int `json:"kick,omitempty"`
	BanPtr    *int `json:"ban,omitempty"`
	RedactPtr *int `json:"redact,omitempty"`
	// contains filtered or unexported fields
}

func (*PowerLevels) Ban

func (pl *PowerLevels) Ban() int

func (*PowerLevels) EnsureEventLevel

func (pl *PowerLevels) EnsureEventLevel(eventType EventType, level int) bool

func (*PowerLevels) EnsureUserLevel

func (pl *PowerLevels) EnsureUserLevel(userID string, level int) bool

func (*PowerLevels) GetEventLevel

func (pl *PowerLevels) GetEventLevel(eventType EventType) int

func (*PowerLevels) GetUserLevel

func (pl *PowerLevels) GetUserLevel(userID string) int

func (*PowerLevels) Invite

func (pl *PowerLevels) Invite() int

func (*PowerLevels) Kick

func (pl *PowerLevels) Kick() int

func (*PowerLevels) Redact

func (pl *PowerLevels) Redact() int

func (*PowerLevels) SetEventLevel

func (pl *PowerLevels) SetEventLevel(eventType EventType, level int)

func (*PowerLevels) SetUserLevel

func (pl *PowerLevels) SetUserLevel(userID string, level int)

func (*PowerLevels) StateDefault

func (pl *PowerLevels) StateDefault() int

type RelatesTo

type RelatesTo struct {
	InReplyTo InReplyTo `json:"m.in_reply_to,omitempty"`
}

type ReqBanUser

type ReqBanUser struct {
	Reason string `json:"reason,omitempty"`
	UserID string `json:"user_id"`
}

ReqBanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban

type ReqCreateRoom

type ReqCreateRoom struct {
	Visibility      string                 `json:"visibility,omitempty"`
	RoomAliasName   string                 `json:"room_alias_name,omitempty"`
	Name            string                 `json:"name,omitempty"`
	Topic           string                 `json:"topic,omitempty"`
	Invite          []string               `json:"invite,omitempty"`
	Invite3PID      []ReqInvite3PID        `json:"invite_3pid,omitempty"`
	CreationContent map[string]interface{} `json:"creation_content,omitempty"`
	InitialState    []*Event               `json:"initial_state,omitempty"`
	Preset          string                 `json:"preset,omitempty"`
	IsDirect        bool                   `json:"is_direct,omitempty"`
}

ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom

type ReqInvite3PID

type ReqInvite3PID struct {
	IDServer string `json:"id_server"`
	Medium   string `json:"medium"`
	Address  string `json:"address"`
}

ReqInvite3PID is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#id57 It is also a JSON object used in https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom

type ReqInviteUser

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

ReqInviteUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite

type ReqKickUser

type ReqKickUser struct {
	Reason string `json:"reason,omitempty"`
	UserID string `json:"user_id"`
}

ReqKickUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick

type ReqLogin

type ReqLogin struct {
	Type                     string `json:"type"`
	Password                 string `json:"password,omitempty"`
	Medium                   string `json:"medium,omitempty"`
	User                     string `json:"user,omitempty"`
	Address                  string `json:"address,omitempty"`
	Token                    string `json:"token,omitempty"`
	DeviceID                 string `json:"device_id,omitempty"`
	InitialDeviceDisplayName string `json:"initial_device_display_name,omitempty"`
}

ReqLogin is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login

type ReqPresence

type ReqPresence struct {
	Presence string `json:"presence"`
}

type ReqRedact

type ReqRedact struct {
	Reason string `json:"reason,omitempty"`
}

ReqRedact is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid

type ReqRegister

type ReqRegister struct {
	Username                 string      `json:"username,omitempty"`
	BindEmail                bool        `json:"bind_email,omitempty"`
	Password                 string      `json:"password,omitempty"`
	DeviceID                 string      `json:"device_id,omitempty"`
	InitialDeviceDisplayName string      `json:"initial_device_display_name"`
	Auth                     interface{} `json:"auth,omitempty"`
}

ReqRegister is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register

type ReqTyping

type ReqTyping struct {
	Typing  bool  `json:"typing"`
	Timeout int64 `json:"timeout,omitempty"`
}

ReqTyping is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid

type ReqUnbanUser

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

ReqUnbanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban

type RespBanUser

type RespBanUser struct{}

RespBanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban

type RespCreateFilter

type RespCreateFilter struct {
	FilterID string `json:"filter_id"`
}

RespCreateFilter is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter

type RespCreateRoom

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

RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom

type RespError

type RespError struct {
	ErrCode string `json:"errcode"`
	Err     string `json:"error"`
}

RespError is the standard JSON error response from Homeservers. It also implements the Golang "error" interface. See http://matrix.org/docs/spec/client_server/r0.2.0.html#api-standards

func (RespError) Error

func (e RespError) Error() string

Error returns the errcode and error message.

type RespForgetRoom

type RespForgetRoom struct{}

RespForgetRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget

type RespInviteUser

type RespInviteUser struct{}

RespInviteUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite

type RespJoinRoom

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

RespJoinRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join

type RespJoinedMembers

type RespJoinedMembers struct {
	Joined map[string]struct {
		DisplayName *string `json:"display_name"`
		AvatarURL   *string `json:"avatar_url"`
	} `json:"joined"`
}

RespJoinedMembers is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680

type RespJoinedRooms

type RespJoinedRooms struct {
	JoinedRooms []string `json:"joined_rooms"`
}

RespJoinedRooms is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680

type RespKickUser

type RespKickUser struct{}

RespKickUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick

type RespLeaveRoom

type RespLeaveRoom struct{}

RespLeaveRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave

type RespLogin

type RespLogin struct {
	AccessToken string `json:"access_token"`
	DeviceID    string `json:"device_id"`
	HomeServer  string `json:"home_server"`
	UserID      string `json:"user_id"`
}

RespLogin is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login

type RespLogout

type RespLogout struct{}

RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout

type RespMediaUpload

type RespMediaUpload struct {
	ContentURI string `json:"content_uri"`
}

RespMediaUpload is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload

type RespMessages

type RespMessages struct {
	Start string   `json:"start"`
	Chunk []*Event `json:"chunk"`
	End   string   `json:"end"`
}

RespMessages is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages

type RespRegister

type RespRegister struct {
	AccessToken  string `json:"access_token"`
	DeviceID     string `json:"device_id"`
	HomeServer   string `json:"home_server"`
	RefreshToken string `json:"refresh_token"`
	UserID       string `json:"user_id"`
}

RespRegister is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register

type RespSendEvent

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

RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid

type RespSync

type RespSync struct {
	NextBatch   string `json:"next_batch"`
	AccountData struct {
		Events []*Event `json:"events"`
	} `json:"account_data"`
	Presence struct {
		Events []*Event `json:"events"`
	} `json:"presence"`
	Rooms struct {
		Leave map[string]struct {
			State struct {
				Events []*Event `json:"events"`
			} `json:"state"`
			Timeline struct {
				Events    []*Event `json:"events"`
				Limited   bool     `json:"limited"`
				PrevBatch string   `json:"prev_batch"`
			} `json:"timeline"`
		} `json:"leave"`
		Join map[string]struct {
			State struct {
				Events []*Event `json:"events"`
			} `json:"state"`
			Timeline struct {
				Events    []*Event `json:"events"`
				Limited   bool     `json:"limited"`
				PrevBatch string   `json:"prev_batch"`
			} `json:"timeline"`
			Ephemeral struct {
				Events []*Event `json:"events"`
			} `json:"ephemeral"`
			AccountData struct {
				Events []*Event `json:"events"`
			} `json:"account_data"`
		} `json:"join"`
		Invite map[string]struct {
			State struct {
				Events []*Event `json:"events"`
			} `json:"invite_state"`
		} `json:"invite"`
	} `json:"rooms"`
}

RespSync is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync

type RespTurnServer

type RespTurnServer struct {
	Username string   `json:"username"`
	Password string   `json:"password"`
	TTL      int      `json:"ttl"`
	URIs     []string `json:"uris"`
}

type RespUnbanUser

type RespUnbanUser struct{}

RespUnbanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban

type RespUserDisplayName

type RespUserDisplayName struct {
	DisplayName string `json:"displayname"`
}

RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname

type RespUserInteractive

type RespUserInteractive struct {
	Flows []struct {
		Stages []string `json:"stages"`
	} `json:"flows"`
	Params    map[string]interface{} `json:"params"`
	Session   string                 `json:"string"`
	Completed []string               `json:"completed"`
	ErrCode   string                 `json:"errcode"`
	Error     string                 `json:"error"`
}

RespUserInteractive is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#user-interactive-authentication-api

func (RespUserInteractive) HasSingleStageFlow

func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool

HasSingleStageFlow returns true if there exists at least 1 Flow with a single stage of stageName.

type RespVersions

type RespVersions struct {
	Versions []string `json:"versions"`
}

RespVersions is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions

type Room

type Room struct {
	ID    string
	State map[EventType]map[string]*Event
}

Room represents a single Matrix room.

func NewRoom

func NewRoom(roomID string) *Room

NewRoom creates a new Room with the given ID

func (Room) GetMembershipState

func (room Room) GetMembershipState(userID string) Membership

GetMembershipState returns the membership state of the given user ID in this room. If there is no entry for this member, 'leave' is returned for consistency with left users.

func (Room) GetStateEvent

func (room Room) GetStateEvent(eventType EventType, stateKey string) *Event

GetStateEvent returns the state event for the given type/state_key combo, or nil.

func (Room) UpdateState

func (room Room) UpdateState(event *Event)

UpdateState updates the room's current state with the given Event. This will clobber events based on the type/state_key combination.

type RoomFilter

type RoomFilter struct {
	AccountData  FilterPart `json:"account_data,omitempty"`
	Ephemeral    FilterPart `json:"ephemeral,omitempty"`
	IncludeLeave bool       `json:"include_leave,omitempty"`
	NotRooms     []string   `json:"not_rooms,omitempty"`
	Rooms        []string   `json:"rooms,omitempty"`
	State        FilterPart `json:"state,omitempty"`
	Timeline     FilterPart `json:"timeline,omitempty"`
}

RoomFilter is used to define filtering rules for room events

type RoomName

type RoomName struct {
	Name string `json:"name,omitempty"`
}

type RoomTopic

type RoomTopic struct {
	Topic string `json:"topic,omitempty"`
}

type Storer

type Storer interface {
	SaveFilterID(userID, filterID string)
	LoadFilterID(userID string) string
	SaveNextBatch(userID, nextBatchToken string)
	LoadNextBatch(userID string) string
	SaveRoom(room *Room)
	LoadRoom(roomID string) *Room
}

Storer is an interface which must be satisfied to store client data.

You can either write a struct which persists this data to disk, or you can use the provided "InMemoryStore" which just keeps data around in-memory which is lost on restarts.

type StrippedState

type StrippedState struct {
	Content  Content   `json:"content"`
	Type     EventType `json:"type"`
	StateKey string    `json:"state_key"`
}

type Syncer

type Syncer interface {
	// Process the /sync response. The since parameter is the since= value that was used to produce the response.
	// This is useful for detecting the very first sync (since=""). If an error is return, Syncing will be stopped
	// permanently.
	ProcessResponse(resp *RespSync, since string) error
	// OnFailedSync returns either the time to wait before retrying or an error to stop syncing permanently.
	OnFailedSync(res *RespSync, err error) (time.Duration, error)
	// GetFilterJSON for the given user ID. NOT the filter ID.
	GetFilterJSON(userID string) json.RawMessage
}

Syncer represents an interface that must be satisfied in order to do /sync requests on a client.

type Tags

type Tags map[string]struct {
	Order string `json:"order"`
}

type ThirdPartyInvite

type ThirdPartyInvite struct {
	DisplayName string `json:"display_name"`
	Signed      struct {
		Token      string          `json:"token"`
		Signatures json.RawMessage `json:"signatures"`
		MXID       string          `json:"mxid"`
	}
}

type Unsigned

type Unsigned struct {
	PrevContent   *Content `json:"prev_content,omitempty"`
	PrevSender    string   `json:"prev_sender,omitempty"`
	ReplacesState string   `json:"replaces_state,omitempty"`
	Age           int64    `json:"age,omitempty"`

	PassiveCommand map[string]*MatchedPassiveCommand `json:"m.passive_command,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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