Documentation
¶
Overview ¶
Package linkpearl represents the library itself
Index ¶
- Constants
- Variables
- func EventContains[T comparable](evt *event.Event, field string, value T) bool
- func EventField[T comparable](content *event.Content, field string) T
- func EventParent(currentID id.EventID, content event.Relatable) id.EventID
- func EventRelatesTo(evt *event.Event) *event.RelatesTo
- func GetParent(evt *event.Event) id.EventID
- func ParseContent(evt *event.Event, log *zerolog.Logger)
- func RelatesTo(parentID id.EventID, noThreads ...bool) *event.RelatesTo
- func UnwrapError(err error) error
- type Config
- type Crypter
- type Linkpearl
- func (l *Linkpearl) FindEventBy(ctx context.Context, roomID id.RoomID, fieldValue map[string]string, ...) *event.Event
- func (l *Linkpearl) FindThreadBy(ctx context.Context, roomID id.RoomID, fieldValue map[string]string, ...) *event.Event
- func (l *Linkpearl) GetAccountData(ctx context.Context, name string) (map[string]string, error)
- func (l *Linkpearl) GetAccountDataCrypter() *Crypter
- func (l *Linkpearl) GetClient() *mautrix.Client
- func (l *Linkpearl) GetDB() *sql.DB
- func (l *Linkpearl) GetMachine() *crypto.OlmMachine
- func (l *Linkpearl) GetRoomAccountData(ctx context.Context, roomID id.RoomID, name string) (map[string]string, error)
- func (l *Linkpearl) OnEvent(callback mautrix.EventHandler)
- func (l *Linkpearl) OnEventType(eventType event.Type, callback mautrix.EventHandler)
- func (l *Linkpearl) OnSync(callback mautrix.SyncHandler)
- func (l *Linkpearl) RedactReaction(ctx context.Context, roomID id.RoomID, eventID id.EventID, reaction string) error
- func (l *Linkpearl) Relations(ctx context.Context, roomID id.RoomID, eventID id.EventID, relType string, ...) (*RespRelations, error)
- func (l *Linkpearl) ReplaceReaction(ctx context.Context, roomID id.RoomID, eventID id.EventID, ...) error
- func (l *Linkpearl) Send(ctx context.Context, roomID id.RoomID, content any) (id.EventID, error)
- func (l *Linkpearl) SendFile(ctx context.Context, roomID id.RoomID, req *mautrix.ReqUploadMedia, ...) error
- func (l *Linkpearl) SendMessageEvent(ctx context.Context, roomID id.RoomID, eventType event.Type, contentJSON any, ...) (resp *mautrix.RespSendEvent, err error)
- func (l *Linkpearl) SendNotice(ctx context.Context, roomID id.RoomID, message string, ...)
- func (l *Linkpearl) SendReaction(ctx context.Context, roomID id.RoomID, eventID id.EventID, reaction string) error
- func (l *Linkpearl) SendTyping(ctx context.Context, roomID id.RoomID, typing bool, timeout ...int)
- func (l *Linkpearl) SetAccountData(ctx context.Context, name string, data map[string]string) error
- func (l *Linkpearl) SetJoinPermit(value func(context.Context, *event.Event) bool)
- func (l *Linkpearl) SetRoomAccountData(ctx context.Context, roomID id.RoomID, name string, data map[string]string) error
- func (l *Linkpearl) Start(ctx context.Context, optionalStatusMsg ...string) error
- func (l *Linkpearl) Stop(ctx context.Context)
- func (l *Linkpearl) Threads(ctx context.Context, roomID id.RoomID, fromToken ...string) (*RespThreads, error)
- type ReqPresence
- type RespRelations
- type RespThreads
Constants ¶
const ( // DefaultMaxRetries for operations like autojoin DefaultMaxRetries = 10 // DefaultAccountDataCache size DefaultAccountDataCache = 1000 // DefaultEventsLimit for methods like lp.Threads() and lp.FindEventBy() DefaultEventsLimit = 1000 // DefaultTypingTimeout in seconds for typing notifications DefaultTypingTimeout = 60 // DefaultUserAgent for HTTP requests DefaultUserAgent = "Linkpearl (library; +https://gitlab.com/etke.cc/linkpearl)" )
const ( // MaxRetries is the maximum number of retries for sending a message MaxRetries = 5 // DefaultTypingTimeout is the step delay for sending message retries RetryDelay = 5 * time.Second )
Variables ¶
var ErrInvalidData = errors.New("invalid data")
ErrInvalidData returned in provided encrypted data (ciphertext) is invalid
Functions ¶
func EventContains ¶
func EventContains[T comparable](evt *event.Event, field string, value T) bool
EventContains checks if raw event content contains specified field with specified values
func EventField ¶
func EventField[T comparable](content *event.Content, field string) T
EventField returns field value from raw event content
func EventParent ¶
EventParent returns parent event ID (either from thread or from reply-to relation), like GetRelatesTo(), but with content and default return value
func EventRelatesTo ¶
EventRelatesTo uses evt as source for EventParent() and RelatesTo()
func GetParent ¶
GetParent is nil-safe version of evt.Content.AsMessage().RelatesTo.(GetThreadParent()|GetReplyTo())
func ParseContent ¶
ParseContent parses event content according to evt.Type
func RelatesTo ¶
RelatesTo returns relation object of a matrix event (either threads with reply-to fallback or plain reply-to)
func UnwrapError ¶
UnwrapError tries to unwrap a error into something meaningful, like mautrix.HTTPError or mautrix.RespError
Types ¶
type Config ¶
type Config struct { // Homeserver url Homeserver string // Login is a localpart for password auth or full mxid for shared secret auth (honoroit - for password, @honoroit:example.com - for shared secret) Login string // Password for login/password auth only Password string SharedSecret string // JoinPermit is a callback function that tells // if linkpearl should respond to the given "invite" event // and join the room JoinPermit func(context.Context, *event.Event) bool // AutoLeave if true, linkpearl will automatically leave empty rooms AutoLeave bool // AccountDataCache size AccountDataCache int // AccountDataSecret (Password) for encryption AccountDataSecret string // MaxRetries for operations like auto join MaxRetries int // EventsLimit for methods like lp.Threads() or lp.FindEventBy() EventsLimit int // UserAgent for requests UserAgent string // Logger Logger zerolog.Logger // DB object DB *sql.DB // Dialect of the DB: postgres, sqlite3 Dialect string }
Config represents matrix config
type Crypter ¶
type Crypter struct {
// contains filtered or unexported fields
}
Crypter is special object that handles data encryption and decryption apart from Matrix' standard encryption. It can encrypt and decrypt arbitrary data using secret key (password)
func NewCrypter ¶
NewCrypter creates new Crypter
type Linkpearl ¶
type Linkpearl struct {
// contains filtered or unexported fields
}
Linkpearl object
func (*Linkpearl) FindEventBy ¶
func (l *Linkpearl) FindEventBy(ctx context.Context, roomID id.RoomID, fieldValue map[string]string, fromToken ...string) *event.Event
FindEventBy tries to find message event by field and value
func (*Linkpearl) FindThreadBy ¶
func (l *Linkpearl) FindThreadBy(ctx context.Context, roomID id.RoomID, fieldValue map[string]string, fromToken ...string) *event.Event
FindThreadBy tries to find thread message event by field and value
func (*Linkpearl) GetAccountData ¶
GetAccountData of the user (from cache and API, with encryption support)
func (*Linkpearl) GetAccountDataCrypter ¶
GetAccountDataCrypter returns crypter used for account data (if any)
func (*Linkpearl) GetMachine ¶
func (l *Linkpearl) GetMachine() *crypto.OlmMachine
GetMachine returns underlying OLM machine
func (*Linkpearl) GetRoomAccountData ¶
func (l *Linkpearl) GetRoomAccountData(ctx context.Context, roomID id.RoomID, name string) (map[string]string, error)
GetRoomAccountData of the room (from cache and API, with encryption support)
func (*Linkpearl) OnEvent ¶
func (l *Linkpearl) OnEvent(callback mautrix.EventHandler)
OnEvent shortcut to mautrix.DefaultSyncer.OnEvent
func (*Linkpearl) OnEventType ¶
func (l *Linkpearl) OnEventType(eventType event.Type, callback mautrix.EventHandler)
OnEventType allows callers to be notified when there are new events for the given event type. There are no duplicate checks.
func (*Linkpearl) OnSync ¶
func (l *Linkpearl) OnSync(callback mautrix.SyncHandler)
OnSync shortcut to mautrix.DefaultSyncer.OnSync
func (*Linkpearl) RedactReaction ¶
func (l *Linkpearl) RedactReaction(ctx context.Context, roomID id.RoomID, eventID id.EventID, reaction string) error
RedactReaction redacts a reaction from a message
func (*Linkpearl) Relations ¶
func (l *Linkpearl) Relations(ctx context.Context, roomID id.RoomID, eventID id.EventID, relType string, fromToken ...string) (*RespRelations, error)
Relations returns all relations of the given type for the given event
func (*Linkpearl) ReplaceReaction ¶
func (l *Linkpearl) ReplaceReaction(ctx context.Context, roomID id.RoomID, eventID id.EventID, oldReaction, newReaction string) error
ReplaceReaction replaces a reaction with another
func (*Linkpearl) Send ¶
Send a message to the roomID and automatically try to encrypt it, if the destination room is encrypted
func (*Linkpearl) SendFile ¶
func (l *Linkpearl) SendFile(ctx context.Context, roomID id.RoomID, req *mautrix.ReqUploadMedia, msgtype event.MessageType, relates ...*event.RelatesTo) error
SendFile to a matrix room
func (*Linkpearl) SendMessageEvent ¶
func (l *Linkpearl) SendMessageEvent(ctx context.Context, roomID id.RoomID, eventType event.Type, contentJSON any, currentAttempt ...int) (resp *mautrix.RespSendEvent, err error)
SendMessageEvent sends a message event to the roomID and automatically retries if the server returns a 502 or 404 error
func (*Linkpearl) SendNotice ¶
func (l *Linkpearl) SendNotice(ctx context.Context, roomID id.RoomID, message string, relates ...*event.RelatesTo)
SendNotice to a room with optional relations, markdown supported
func (*Linkpearl) SendReaction ¶
func (l *Linkpearl) SendReaction(ctx context.Context, roomID id.RoomID, eventID id.EventID, reaction string) error
SendReaction sends a reaction to a message
func (*Linkpearl) SendTyping ¶
SendTyping notification
func (*Linkpearl) SetAccountData ¶
SetAccountData of the user (to cache and API, with encryption support)
func (*Linkpearl) SetJoinPermit ¶
SetJoinPermit sets the join permit callback function
func (*Linkpearl) SetRoomAccountData ¶
func (l *Linkpearl) SetRoomAccountData(ctx context.Context, roomID id.RoomID, name string, data map[string]string) error
SetRoomAccountData of the room (to cache and API, with encryption support)
type ReqPresence ¶
type RespRelations ¶
type RespRelations struct { Chunk []*event.Event `json:"chunk"` NextBatch string `json:"next_batch"` }
RespRelations is response of https://spec.matrix.org/v1.8/client-server-api/#get_matrixclientv1roomsroomidrelationseventidreltype
type RespThreads ¶
type RespThreads struct { Chunk []*event.Event `json:"chunk"` NextBatch string `json:"next_batch"` }
RespThreads is response of https://spec.matrix.org/v1.8/client-server-api/#get_matrixclientv1roomsroomidthreads