Documentation ¶
Index ¶
- Constants
- Variables
- func Base64UserID(uID matrix.UserID) string
- func Cancelled() context.Context
- func LatestMessage(events []event.RoomEvent) *event.RoomMessageEvent
- func MXCProvider(w, h int, flags ImageFlags) imgutil.Provider
- func MaxSize(w, h, maxW, maxH int) (int, int)
- func WithClient(ctx context.Context, c *Client) context.Context
- type Client
- func (c *Client) AddHandler(function interface{}) errordeprecated
- func (c *Client) AddSyncInterceptFull(f httptrick.InterceptFullFunc) func()
- func (c *Client) AsyncSetConfig(ev event.Event, done func(error))
- func (c *Client) Close() error
- func (c *Client) EachRoomState(roomID matrix.RoomID, typ event.Type, f func(string, event.StateEvent) error) errordeprecated
- func (c *Client) EachRoomStateLen(roomID matrix.RoomID, typ event.Type, ...) error
- func (c *Client) EachTimeline(roomID matrix.RoomID, f func(event.RoomEvent) error) error
- func (c *Client) EachTimelineReverse(roomID matrix.RoomID, f func(event.RoomEvent) error) error
- func (c *Client) HasPower(roomID matrix.RoomID, action PowerAction) bool
- func (c *Client) ImageThumbnail(msg *event.RoomMessageEvent, maxW, maxH, scale int) (string, error)
- func (c *Client) IsDirect(roomID matrix.RoomID) bool
- func (c *Client) IsRoomCreator(roomID matrix.RoomID) bool
- func (c *Client) MarkRoomAsRead(roomID matrix.RoomID, eventID matrix.EventID) error
- func (c *Client) MemberName(roomID matrix.RoomID, userID matrix.UserID, check bool) (MemberName, error)
- func (c *Client) MessageMediaURL(msg *event.RoomMessageEvent) (string, error)
- func (c *Client) NotifyMessage(msg *event.RoomMessageEvent, action NotifyMessageAction) NotifyMessageAction
- func (c *Client) Offline() *Client
- func (c *Client) Online(ctx context.Context) *Client
- func (c *Client) Open() error
- func (c *Client) Redact(roomID matrix.RoomID, ev matrix.EventID, reason string) error
- func (c *Client) RoomCountUnread(roomID matrix.RoomID) (n int, more bool)
- func (c *Client) RoomEnsureMembers(roomID matrix.RoomID) error
- func (c *Client) RoomEvent(roomID matrix.RoomID, typ event.Type) (event.Event, error)
- func (c *Client) RoomIsSpace(roomID matrix.RoomID) bool
- func (c *Client) RoomLatestReadEvent(roomID matrix.RoomID) matrix.EventID
- func (c *Client) RoomMembers(roomID matrix.RoomID) ([]event.RoomMemberEvent, error)
- func (c *Client) RoomName(roomID matrix.RoomID) (string, error)
- func (c *Client) RoomPaginator(roomID matrix.RoomID, limit int) *RoomPaginator
- func (c *Client) RoomState(roomID matrix.RoomID, typ event.Type, key string) (event.StateEvent, error)
- func (c *Client) RoomTimeline(roomID matrix.RoomID) ([]event.RoomEvent, error)
- func (c *Client) RoomTimelineEvent(roomID matrix.RoomID, id matrix.EventID) (event.RoomEvent, error)
- func (c *Client) RoomType(roomID matrix.RoomID) string
- func (c *Client) Rooms() ([]matrix.RoomID, error)
- func (c *Client) ScaledThumbnail(mURL matrix.URL, w, h, scale int) (string, error)
- func (c *Client) SendRoomEvent(roomID matrix.RoomID, ev event.Event) error
- func (c *Client) SquareThumbnail(mURL matrix.URL, size, scale int) (string, error)
- func (c *Client) Thumbnail(mURL matrix.URL, w, h, scale int) (string, error)
- func (c *Client) UpdateRoomTags(roomID matrix.RoomID) error
- func (c *Client) UserEvent(typ event.Type) (event.Event, error)
- func (c *Client) Whoami() (matrix.UserID, error)
- func (c *Client) WithContext(ctx context.Context) *Client
- type ClientAuth
- func (a *ClientAuth) LoginMethods() ([]matrix.LoginMethod, error)
- func (a *ClientAuth) LoginPassword(username, password string) (*Client, error)
- func (a *ClientAuth) LoginSSO(done func(*Client, error)) (string, error)
- func (a *ClientAuth) LoginToken(token string) (*Client, error)
- func (a *ClientAuth) WithContext(ctx context.Context) *ClientAuth
- type ConfigPather
- type ImageFlags
- type MemberName
- type NotifyMessageAction
- type Opts
- type PowerAction
- type RoomPaginator
Constants ¶
const TimelimeLimit = state.TimelineKeepLast
TimelimeLimit is the number of timeline events that the database keeps.
Variables ¶
var ( // InfoEnabled is true if GOMATRIX_INFO is non-empty. InfoEnabled bool // WarnEnabled is true if GOMATRIX_WARN is non-empty. WarnEnabled bool )
var AvatarProvider = imgutil.NewProviders( imgutil.HTTPProvider, MXCProvider(128, 128, ImageNormal|ImageSkip1xScale), )
AvatarProvider is the image provider that all avatar widgets should use.
var DefaultTransport = &http.Transport{ Proxy: http.ProxyFromEnvironment, ForceAttemptHTTP2: true, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, WriteBufferSize: 256 << 10, ReadBufferSize: 256 << 10, DialContext: (&net.Dialer{ Timeout: 10 * time.Second, }).DialContext, }
DefaultTransport is the default HTTP transport configuration to use.
A few notes:
- We use a high ResponseHeaderTimeout because the server presumably won't send us a header while it's preparing the response to be sent. We don't want to mark the connection as timed out.
var EachBreak = db.EachBreak
EachBreak can be returned if the user wants to break out of an interation.
var SyncOptions = gotrix.SyncOptions{ Filter: event.GlobalFilter{ Room: event.RoomFilter{ State: event.StateFilter{ LazyLoadMembers: true, IncludeRedundantMembers: true, }, Timeline: event.RoomEventFilter{ Limit: TimelimeLimit, LazyLoadMembers: true, }, }, }, Timeout: 1 * time.Minute, MinBackoffTime: 1 * time.Second, MaxBackoffTime: 10 * time.Second, }
SyncOptions is used to sync.
Functions ¶
func Base64UserID ¶
Base64UserID creates a path-friendly base64 string from the given user ID.
func LatestMessage ¶
func LatestMessage(events []event.RoomEvent) *event.RoomMessageEvent
LatestMessage finds the latest room message event from the given list of events. The list is assumed to have the latest events last.
func MXCProvider ¶ added in v0.1.3
func MXCProvider(w, h int, flags ImageFlags) imgutil.Provider
MXCProvider returns a new universal resource provider that handles MXC URLs.
Types ¶
type Client ¶
type Client struct { *gotrix.Client *handler.Registry State *state.State Index *indexer.Indexer Interceptor *httptrick.Interceptor // contains filtered or unexported fields }
Client extends a gotrix.Client to implement additional functions useful for gotktrix.
func FromContext ¶
FromContext returns the client inside the context wrapped with WithClient. If the context isn't yet wrapped, then nil is returned.
func (*Client) AddHandler
deprecated
func (*Client) AddSyncInterceptFull ¶
func (c *Client) AddSyncInterceptFull(f httptrick.InterceptFullFunc) func()
AddSyncInterceptFull adds an InterceptFullFunc for the Sync endpoint.
func (*Client) AsyncSetConfig ¶
AsyncSetConfig updates the state cache first, and then updates the API in the background.
If done is given, then it's called once the API is updated. Most of the time, done should only be used to display errors; to know when things are updated, use a handler. Because of that, done may be invoked before AsyncConfigSet has been returned when there's an error. Done might also be called in a different goroutine.
func (*Client) Close ¶
Close closes the event loop and the internal database, as well as halting all ongoing requests.
func (*Client) EachRoomState
deprecated
func (c *Client) EachRoomState( roomID matrix.RoomID, typ event.Type, f func(string, event.StateEvent) error) error
EachRoomState calls f on every raw event in the room state. It satisfies the EachRoomState method requirement inside gotrix.State, but most callers should not use this method, since there is no length information.
Deprecated: Use EachRoomStateLen.
func (*Client) EachRoomStateLen ¶
func (c *Client) EachRoomStateLen( roomID matrix.RoomID, typ event.Type, f func(ev event.StateEvent, total int) error) error
EachRoomStateLen is a variant of EachRoomState, but a length parameter is precalculated.
func (*Client) EachTimeline ¶
EachTimeline iterates through the timeline.
func (*Client) EachTimelineReverse ¶
EachTimelineReverse iterates through the timeline in reverse.
func (*Client) HasPower ¶
func (c *Client) HasPower(roomID matrix.RoomID, action PowerAction) bool
HasPower checks if the current user can perform the given action inside the given room.
func (*Client) ImageThumbnail ¶
ImageThumbnail gets the thumbnail or direct URL of the image from the message.
func (*Client) IsRoomCreator ¶
IsRoomCreator returns true if the current user is the user who made this room.
func (*Client) MarkRoomAsRead ¶
MarkRoomAsRead sends to the server that the current user has seen up to the given event in the given room.
func (*Client) MemberName ¶
func (c *Client) MemberName( roomID matrix.RoomID, userID matrix.UserID, check bool) (MemberName, error)
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.
If check is true, then the MemberName's Ambiguous field will be set to true if the display name collides with someone else's. This check is quite expensive, so it should only be enabled when needed.
func (*Client) MessageMediaURL ¶
func (c *Client) MessageMediaURL(msg *event.RoomMessageEvent) (string, error)
MessageMediaURL gets the message's media URL, if any.
func (*Client) NotifyMessage ¶
func (c *Client) NotifyMessage(msg *event.RoomMessageEvent, action NotifyMessageAction) NotifyMessageAction
NotifyMessage returns true if msg should be notified with action. The returned NotifyMessageAction contains enabled bits for the actions that the found rule wants.
Note that this isn't perfect: only a single rule is accounted for, which is the first one that happens to match the message, so some conditions may be missed.
func (*Client) Online ¶
Online returns a Client that uses the given context instead of the cancelled context. It is an alias to WithContext; the only difference is that the name implies the client may be offline prior to this call.
func (*Client) RoomCountUnread ¶
RoomCountUnread counts the number of unread events in a room. More is true if the user has never seen any of the messages in the room. The user should display that info as "${n}+" with the trailing plus.
func (*Client) RoomEnsureMembers ¶
RoomEnsureMembers ensures that the given room has all its members fetched.
func (*Client) RoomEvent ¶
RoomEvent queries the event with the given type. If the event type implies a state event, then the empty key is tried.
func (*Client) RoomIsSpace ¶
RoomIsSpace returns true if the room with the given ID is a space-room.
func (*Client) RoomLatestReadEvent ¶
RoomLatestReadEvent gets the latest read eventID. The event ID is an empty string if the user hasn't read anything.
func (*Client) RoomMembers ¶
RoomMembers returns a list of room members.
func (*Client) RoomPaginator ¶
func (c *Client) RoomPaginator(roomID matrix.RoomID, limit int) *RoomPaginator
RoomPaginator returns a new paginator that can fetch messages from the bottom up.
func (*Client) RoomState ¶
func (c *Client) RoomState( roomID matrix.RoomID, typ 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) RoomTimeline ¶
RoomTimeline queries the state cache for the timeline of the given room. If it's not available, the API will be queried directly. The order of these events is guaranteed to be latest last.
func (*Client) RoomTimelineEvent ¶ added in v0.1.3
func (c *Client) RoomTimelineEvent(roomID matrix.RoomID, id matrix.EventID) (event.RoomEvent, error)
RoomTimelineEvent fetches a single room timeline event by its ID.
func (*Client) RoomType ¶
RoomType returns the room's type. An empty string signifies a regular room.
func (*Client) ScaledThumbnail ¶
ScaledThumbnail is like Thumbnail, except the image URL in the image respects the original aspect ratio and not the requested one.
func (*Client) SendRoomEvent ¶
SendRoomEvent is a convenient function around RoomEventSend.
func (*Client) SquareThumbnail ¶
SquareThumbnail is a helper function around MediaThumbnailURL. The given size is assumed to be a square, and the size will be scaled up to the next power of 2 and multiplied up for ensured HiDPI support of up to 2x.
func (*Client) Thumbnail ¶
Thumbnail is a helper function around MediaThumbnailURL. It works similarly to SquareThumbnail, except the dimensions are unchanged.
func (*Client) UpdateRoomTags ¶
UpdateRoomTags updates the internal state with the latest room tag information.
type ClientAuth ¶
type ClientAuth struct {
// contains filtered or unexported fields
}
ClientAuth holds a partial client.
func Discover ¶
func Discover(serverName string, opts Opts) (*ClientAuth, error)
Discover wraps around gotrix.DiscoverWithClienT.
func (*ClientAuth) LoginMethods ¶
func (a *ClientAuth) LoginMethods() ([]matrix.LoginMethod, error)
LoginMethods returns the login methods supported by the homeserver.
func (*ClientAuth) LoginPassword ¶
func (a *ClientAuth) LoginPassword(username, password string) (*Client, error)
LoginPassword authenticates the client using the provided username and password.
func (*ClientAuth) LoginSSO ¶
func (a *ClientAuth) LoginSSO(done func(*Client, error)) (string, error)
LoginSSO returns the HTTP address for logging in as SSO and the channel indicating if the user is done or not.
func (*ClientAuth) LoginToken ¶
func (a *ClientAuth) LoginToken(token string) (*Client, error)
LoginToken authenticates the client using the provided token.
func (*ClientAuth) WithContext ¶
func (a *ClientAuth) WithContext(ctx context.Context) *ClientAuth
WithContext creates a copy of ClientAuth that uses the provided context.
type ConfigPather ¶ added in v0.1.3
ConfigPather is an interface describing any instance that can generate a ConfigPath for gotktrix. Realistically, app.Application implements this.
type ImageFlags ¶ added in v0.1.3
type ImageFlags uint8
ImageFlags is describes boolean attributes for fetching Matrix images.
const ( // ImageNormal is the 0 flag. ImageNormal ImageFlags = 0 // MatrixNoCrop asks the server to scale the image down to fit the frame // instead of cropping the image. ImageNoCrop ImageFlags = 1 << (iota - 1) // ImageSkip1xScale skips the 1x scale factor. This is useful if the // specified image size is large enough for either 1x or 2x, since it works // better with the image cache. ImageSkip1xScale )
func (ImageFlags) Has ¶ added in v0.1.3
func (f ImageFlags) Has(this ImageFlags) bool
Has returns true if f has this.
type MemberName ¶
MemberName describes a member name.
type NotifyMessageAction ¶
type NotifyMessageAction uint8
NotifyMessageAction is a simple enum to determine what kind of notification action the application should do.
const ( NotifyMessage NotifyMessageAction = 1 << iota NotifySoundMessage HighlightMessage )
type Opts ¶ added in v0.1.3
type Opts struct { Client httputil.Client ConfigPath ConfigPather }
Opts describes the client options when constructing.
type PowerAction ¶
type PowerAction uint8
PowerAction describes 1 out of the 4 actions in a PowerLevels event.
const ( BanAction PowerAction InviteAction KickAction RedactAction )
type RoomPaginator ¶
type RoomPaginator struct {
// contains filtered or unexported fields
}
RoomPaginator is used to fetch older messages from the API client.
Directories ¶
Path | Synopsis |
---|---|
events
|
|
emojis
Package emojis provides an implementation of the im.ponies emoji protocol.
|
Package emojis provides an implementation of the im.ponies emoji protocol. |
m
Package m provides Matrix-namespace events.
|
Package m provides Matrix-namespace events. |
pronouns
Package pronouns provides an implementation of the pronouns personal protocol.
|
Package pronouns provides an implementation of the pronouns personal protocol. |
sys
Package sys works around the shortcomings of gotrix/event.
|
Package sys works around the shortcomings of gotrix/event. |
internal
|
|