Documentation ¶
Index ¶
- Variables
- type Client
- func (c *Client) AddHandler(function interface{}) error
- func (c *Client) Close() error
- func (c *Client) EachRoomState(roomID matrix.RoomID, typ event.Type, f func(string, event.StateEvent) error) error
- func (c *Client) LoginPassword(username, password string) error
- func (c *Client) LoginSSO() (string, func() error, error)
- func (c *Client) LoginToken(token string) error
- func (c *Client) MarkRoomAsDM(remoteID matrix.UserID, roomID matrix.RoomID) error
- func (c *Client) MemberAvatar(roomID matrix.RoomID, userID matrix.UserID) (*matrix.URL, error)
- func (c *Client) MemberName(roomID matrix.RoomID, userID matrix.UserID) (string, error)
- func (c *Client) MemberNames(roomID matrix.RoomID, userIDs []matrix.UserID) ([]string, error)
- func (c *Client) MentionRoom(roomID matrix.RoomID) (body string, formatted string)
- func (c *Client) MentionUser(userID matrix.UserID, roomID matrix.RoomID) (body string, formatted string)
- func (c *Client) Next() string
- func (c *Client) Open() error
- func (c *Client) OpenWithNext(next string) error
- func (c *Client) RoomAvatar(roomID matrix.RoomID) (*matrix.URL, error)
- func (c *Client) RoomName(roomID matrix.RoomID) (string, error)
- func (c *Client) RoomState(roomID matrix.RoomID, eventType event.Type, key string) (event.StateEvent, error)
- func (c *Client) RoomSummary(roomID matrix.RoomID) (api.SyncRoomSummary, error)
- func (c *Client) SendAudio(roomID matrix.RoomID, file File) (matrix.EventID, error)
- func (c *Client) SendEmote(roomID matrix.RoomID, content string) (matrix.EventID, error)
- func (c *Client) SendFile(roomID matrix.RoomID, file File) (matrix.EventID, error)
- func (c *Client) SendImage(roomID matrix.RoomID, file File) (matrix.EventID, error)
- func (c *Client) SendLocation(roomID matrix.RoomID, geoURI matrix.GeoURI, caption string) (matrix.EventID, error)
- func (c *Client) SendMessage(roomID matrix.RoomID, content string) (matrix.EventID, error)
- func (c *Client) SendNotice(roomID matrix.RoomID, content string) (matrix.EventID, error)
- func (c *Client) SendVideo(roomID matrix.RoomID, file File) (matrix.EventID, error)
- func (c Client) WithContext(ctx context.Context) *Client
- type File
- type Handler
- type State
Constants ¶
This section is empty.
Variables ¶
var DefaultFilter = event.GlobalFilter{ Room: event.RoomFilter{ IncludeLeave: false, State: event.StateFilter{ LazyLoadMembers: true, }, Timeline: event.RoomEventFilter{ Limit: eventsToFetchPerRoom, LazyLoadMembers: true, }, }, }
DefaultFilter is the default filter used by the client.
var ErrInvalidStateEvent = errors.New("invalid state event has been returned by homeserver")
ErrInvalidStateEvent is returned by (*Client).RoomState and (*Client).RoomStates when homeserver returns an event that is not a known state event when a state event is expected.
var ErrRoomAvatarNotFound = errors.New("user is alone in the room and a room avatar has not been set")
ErrRoomAvatarNotFound is returned by RoomAvatar when the room avatar cannot be discovered.
var ErrStopIter = errors.New("stop iterating on EachRoomState")
ErrStopIter is an error used to denote that the iteration on EachRoomState should be stopped.
var MemberAvatarNotFound = errors.New("member avatar cannot be found")
MemberAvatarNotFound is returned by MemberAvatar when a member's avatar cannot be determined.
var SuccessHTML = defaultSuccessHTML
SuccessHTML is the HTML displayed when the user successfully logs in through SSO.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { *api.Client Filter event.GlobalFilter Handler Handler State State // contains filtered or unexported fields }
Client is an instance of a higher level client.
func Discover ¶
Discover is a helper function that calls DiscoverWithClient with the default HTTP client.
func DiscoverWithClient ¶
DiscoverWithClient attempts to discover the homeserver using the provided server name.
This allows the host address to be extracted from the user ID and used to discover the homeserver host in a way that is spec-compliant.
func New ¶
New creates a client with the provided host URL and the default HTTP client. It assumes https if the scheme is not provided.
func NewWithClient ¶
NewWithClient creates a client with the provided host URL and the provided client. It assumes https if the scheme is not provided.
func (*Client) AddHandler ¶
AddHandler adds the handler to the list of handlers.
func (*Client) EachRoomState ¶ added in v0.3.0
func (c *Client) EachRoomState(roomID matrix.RoomID, typ event.Type, f func(string, event.StateEvent) error) error
EachRoomState iterates through all events with the specified type, stopping if f returns ErrIterStop.
func (*Client) LoginPassword ¶
LoginPassword authenticates the client using the provided username and password.
func (*Client) LoginSSO ¶ added in v0.3.1
LoginSSO returns a URL that can be used to log the user in through SSO and starts a HTTP server to listen to the response from the homeserver. It automatically cleans up the HTTP server when the context the client has expires or when the user logs in successfully.
The returned function blocks until the login finishes or is canceled and returns an error if the login was unsuccessful.
func (*Client) LoginToken ¶
LoginToken authenticates the client using the provided token.
func (*Client) MarkRoomAsDM ¶ added in v0.3.0
MarkRoomAsDM fetches the DM room list, appends the provided room and reuploads the list. It is the caller's duty to make sure only one instance is called at once.
func (*Client) MemberAvatar ¶ added in v0.3.1
MemberAvatar determines the member's avatar by checking for a room member event with avatar and falling back to their global avatar. An error is returned if the avatar cannot be determined.
func (*Client) MemberName ¶ added in v0.2.0
MemberName calculates the display name of a member. Note that a user joining might invalidate some names if they share the same display name as disambiguation will become necessary.
Use the Client.MemberNames variant when generating member name for multiple users to reduce duplicate work.
func (*Client) MemberNames ¶ added in v0.3.0
MemberNames calculates the display name of all the users provided.
func (*Client) MentionRoom ¶ added in v0.3.0
MentionRoom creates the intended mention format for a room in normal body and formatted body.
func (*Client) MentionUser ¶ added in v0.3.0
func (c *Client) MentionUser(userID matrix.UserID, roomID matrix.RoomID) (body string, formatted string)
MentionUser creates the intended mention format for a user in normal body and formatted body.
func (*Client) Next ¶ added in v0.3.0
Next returns the current Next synchronization argument. Next can ONLY be called once the Client is closed, otherwise a panic will occur.
func (*Client) OpenWithNext ¶ added in v0.3.0
OpenWithNext starts the event loop with the given next string that resumes the sync loop. If next is empty, then an initial sync will be done.
func (*Client) RoomAvatar ¶ added in v0.3.1
RoomAvatar retrieves the avatar of a room. It falls back to the profile picture of the first user to join the room that is not the current user otherwise. If the current user is alone, it returns nil and an error.
func (*Client) RoomState ¶ added in v0.2.0
func (c *Client) RoomState(roomID matrix.RoomID, eventType event.Type, key string) (event.StateEvent, error)
RoomState queries the internal State for the given RoomEvent. If the State does not have that event, it queries the homeserver directly.
func (*Client) RoomSummary ¶ added in v0.3.0
RoomSummary queries the State for the summary of a room, commonly used for generating room name. To follow the room name generation strategy of the specification, use Client.RoomName instead.
func (*Client) SendAudio ¶ added in v0.3.0
SendAudio uploads the provided audio file to the server and sends a message containing it to the designated room.
func (*Client) SendEmote ¶ added in v0.3.0
SendEmote sends a emote to the provided room ID with the provided content.
Emote is a regular message but is sent as someone performing it (/me in IRC).
func (*Client) SendFile ¶ added in v0.3.0
SendFile uploads the provided file to the server and sends a message containing it to the designated room.
func (*Client) SendImage ¶ added in v0.3.0
SendImage uploads the provided image to the server and sends a message containing it to the designated room.
func (*Client) SendLocation ¶ added in v0.3.0
func (c *Client) SendLocation(roomID matrix.RoomID, geoURI matrix.GeoURI, caption string) (matrix.EventID, error)
SendLocation sends the provided location to the provided room ID.
func (*Client) SendMessage ¶
SendMessage sends a message to the provided room ID with the provided content.
func (*Client) SendNotice ¶
SendNotice sends a notice to the provided room ID with the provided content.
Notice are the same as messages except they're not intended to be parsed by bots (ie. other bots' messages).
type File ¶ added in v0.3.0
type File struct { Name string MIMEType string Content io.ReadCloser Caption string // Set to filename if empty. }
File is a file that can be uploaded to Matrix homeserver.
type Handler ¶
type Handler interface { Handle(cli *Client, event event.Event) HandleRaw(cli *Client, event event.RawEvent) AddHandler(toCall interface{}) error }
Handler is the interface that represents the methods the client needs from the handler. An event is always passed into HandleRaw and is passed into Handle when it is successfully parsed.
type State ¶ added in v0.2.0
type State interface { // RoomState returns the latest event in a room with the specified type. // If it is found in the cache, error will be nil. // Note that (nil, nil) should be returned if the cache can be certain the event type never occurred. RoomState(roomID matrix.RoomID, eventType event.Type, stateKey string) (event.StateEvent, error) // EachRoomState calls f for every event stored in the state. // To abort iteration, f should return ErrStopIter. // This function can return the error returned by f or errors while getting data for iteration. EachRoomState(roomID matrix.RoomID, eventType event.Type, f func(key string, e event.StateEvent) error) error // RoomSummary returns the summary of a room as received in sync response. RoomSummary(roomID matrix.RoomID) (api.SyncRoomSummary, error) // AddEvent adds the needed events from the given sync response. // It is up to the implementation to pick and add the needed events inside the response. AddEvents(*api.SyncResponse) error }
State represents the required functions for a state.