matrix

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Overview

Package matrix contains wrappers for mautrix for use by the UI of gomuks.

Index

Constants

This section is empty.

Variables

View Source
var (
	EventNotFoundError = errors.New("event not found")
	RoomNotFoundError  = errors.New("room not found")
)
View Source
var AccountDataGomuksPreferences = event.Type{
	Type:  "net.maunium.gomuks.preferences",
	Class: event.AccountDataEventType,
}
View Source
var ErrCantEditOthersMessage = errors.New("can't edit message sent by someone else")

Functions

This section is empty.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container is a wrapper for a mautrix Client and some other stuff.

It is used for all Matrix calls from the UI and Matrix event handlers.

func NewContainer

func NewContainer(gmx ifc.Gomuks) *Container

NewContainer creates a new Container for the given Gomuks instance.

func (*Container) Client

func (c *Container) Client() *mautrix.Client

Client returns the underlying mautrix Client.

func (*Container) CreateRoom

func (c *Container) CreateRoom(req *mautrix.ReqCreateRoom) (*rooms.Room, error)

CreateRoom attempts to create a new room and join the user.

func (*Container) Crypto

func (c *Container) Crypto() ifc.Crypto

func (*Container) Download

func (c *Container) Download(uri id.ContentURI, file *attachment.EncryptedFile) (data []byte, err error)

Download fetches the given Matrix content (mxc) URL and returns the data, homeserver, file ID and potential errors.

The file will be either read from the media cache (if found) or downloaded from the server.

func (*Container) DownloadToDisk

func (c *Container) DownloadToDisk(uri id.ContentURI, file *attachment.EncryptedFile, target string) (fullPath string, err error)

func (*Container) FetchMembers

func (c *Container) FetchMembers(room *rooms.Room) error

func (*Container) GetCachePath

func (c *Container) GetCachePath(uri id.ContentURI) string

GetCachePath gets the path to the cached version of the given homeserver:fileID combination. The file may or may not exist, use Download() to ensure it has been cached.

func (*Container) GetDownloadURL

func (c *Container) GetDownloadURL(uri id.ContentURI) string

func (*Container) GetEvent

func (c *Container) GetEvent(room *rooms.Room, eventID id.EventID) (*muksevt.Event, error)

func (*Container) GetHistory

func (c *Container) GetHistory(room *rooms.Room, limit int, dbPointer uint64) ([]*muksevt.Event, uint64, error)

GetHistory fetches room history.

func (*Container) GetOrCreateRoom

func (c *Container) GetOrCreateRoom(roomID id.RoomID) *rooms.Room

GetOrCreateRoom gets the room instance stored in the session.

func (*Container) GetRoom

func (c *Container) GetRoom(roomID id.RoomID) *rooms.Room

GetRoom gets the room instance stored in the session.

func (*Container) HandleDirectChatInfo

func (c *Container) HandleDirectChatInfo(_ mautrix.EventSource, evt *event.Event)

func (*Container) HandleEdit

func (c *Container) HandleEdit(room *rooms.Room, editsID id.EventID, editEvent *muksevt.Event)

func (*Container) HandleEncrypted

func (c *Container) HandleEncrypted(source mautrix.EventSource, mxEvent *event.Event)

func (*Container) HandleEncryptedUnsupported added in v0.1.1

func (c *Container) HandleEncryptedUnsupported(source mautrix.EventSource, mxEvent *event.Event)

func (*Container) HandleMembership

func (c *Container) HandleMembership(source mautrix.EventSource, evt *event.Event)

HandleMembership is the event handler for the m.room.member state event.

func (*Container) HandleMessage

func (c *Container) HandleMessage(source mautrix.EventSource, mxEvent *event.Event)

HandleMessage is the event handler for the m.room.message timeline event.

func (*Container) HandlePreferences

func (c *Container) HandlePreferences(source mautrix.EventSource, evt *event.Event)

func (*Container) HandlePushRules

func (c *Container) HandlePushRules(_ mautrix.EventSource, evt *event.Event)

HandlePushRules is the event handler for the m.push_rules account data event.

func (*Container) HandleReaction

func (c *Container) HandleReaction(room *rooms.Room, reactsTo id.EventID, reactEvent *muksevt.Event)

func (*Container) HandleReadReceipt

func (c *Container) HandleReadReceipt(source mautrix.EventSource, evt *event.Event)

func (*Container) HandleRedaction

func (c *Container) HandleRedaction(source mautrix.EventSource, evt *event.Event)

func (*Container) HandleTag

func (c *Container) HandleTag(_ mautrix.EventSource, evt *event.Event)

HandleTag is the event handler for the m.tag account data event.

func (*Container) HandleTyping

func (c *Container) HandleTyping(_ mautrix.EventSource, evt *event.Event)

HandleTyping is the event handler for the m.typing event.

func (*Container) InitClient

func (c *Container) InitClient() error

InitClient initializes the mautrix client and connects to the homeserver specified in the config.

func (*Container) Initialized

func (c *Container) Initialized() bool

Initialized returns whether or not the mautrix client is initialized (see InitClient())

func (*Container) JoinRoom

func (c *Container) JoinRoom(roomID id.RoomID, server string) (*rooms.Room, error)

JoinRoom makes the current user try to join the given room.

func (*Container) LeaveRoom

func (c *Container) LeaveRoom(roomID id.RoomID) error

LeaveRoom makes the current user leave the given room.

func (*Container) Login

func (c *Container) Login(user, password string) error

Login sends a password login request with the given username and password.

func (*Container) Logout

func (c *Container) Logout()

Logout revokes the access token, stops the syncer and calls the OnLogout() method of the UI.

func (*Container) MarkRead

func (c *Container) MarkRead(roomID id.RoomID, eventID id.EventID)

func (*Container) OnLogin

func (c *Container) OnLogin()

OnLogin initializes the syncer and updates the room list.

func (*Container) PasswordLogin

func (c *Container) PasswordLogin(user, password string) error

func (*Container) Preferences

func (c *Container) Preferences() *config.UserPreferences

func (*Container) PrepareMarkdownMessage

func (c *Container) PrepareMarkdownMessage(roomID id.RoomID, msgtype event.MessageType, text, html string, rel *ifc.Relation) *muksevt.Event

func (*Container) PrepareMediaMessage added in v0.2.0

func (c *Container) PrepareMediaMessage(room *rooms.Room, path string, rel *ifc.Relation) (*muksevt.Event, error)

func (*Container) PushRules

func (c *Container) PushRules() *pushrules.PushRuleset

PushRules returns the push notification rules. If no push rules are cached, UpdatePushRules() will be called first.

func (*Container) Redact

func (c *Container) Redact(roomID id.RoomID, eventID id.EventID, reason string) error

func (*Container) SendEvent

func (c *Container) SendEvent(evt *muksevt.Event) (id.EventID, error)

SendMessage sends the given event.

func (*Container) SendPreferencesToMatrix

func (c *Container) SendPreferencesToMatrix()

func (*Container) SendTyping

func (c *Container) SendTyping(roomID id.RoomID, typing bool)

SendTyping sets whether or not the user is typing in the given room.

func (*Container) SingleSignOn

func (c *Container) SingleSignOn() error

func (*Container) Start

func (c *Container) Start()

Start moves the UI to the main view, calls OnLogin() and runs the syncer forever until stopped with Stop()

func (*Container) Stop

func (c *Container) Stop()

Stop stops the Matrix syncer.

func (*Container) UIAFallback added in v0.2.2

func (c *Container) UIAFallback(loginType mautrix.AuthType, sessionID string) error

func (*Container) UpdatePushRules

func (c *Container) UpdatePushRules()

UpdatePushRules fetches the push notification rules from the server and stores them in the current Session object.

func (*Container) UploadMedia added in v0.2.0

func (c *Container) UploadMedia(path string, encrypt bool) (*ifc.UploadedMediaInfo, error)

type GomuksSyncer

type GomuksSyncer struct {
	FirstSyncDone     bool
	InitDoneCallback  func()
	FirstDoneCallback func()
	Progress          ifc.SyncingModal
	// contains filtered or unexported fields
}

func NewGomuksSyncer

func NewGomuksSyncer(rooms *rooms.RoomCache) *GomuksSyncer

NewGomuksSyncer returns an instantiated GomuksSyncer

func (*GomuksSyncer) GetFilterJSON

func (s *GomuksSyncer) GetFilterJSON(_ id.UserID) *mautrix.Filter

GetFilterJSON returns a filter with a timeline limit of 50.

func (*GomuksSyncer) OnEventType

func (s *GomuksSyncer) 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 (*GomuksSyncer) OnFailedSync

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

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

func (*GomuksSyncer) OnSync

func (s *GomuksSyncer) OnSync(callback mautrix.SyncHandler)

func (*GomuksSyncer) ProcessResponse

func (s *GomuksSyncer) ProcessResponse(res *mautrix.RespSync, since string) (err error)

ProcessResponse processes a Matrix sync response.

type HistoryManager

type HistoryManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewHistoryManager

func NewHistoryManager(dbPath string) (*HistoryManager, error)

func (*HistoryManager) Append

func (hm *HistoryManager) Append(room *rooms.Room, events []*event.Event) ([]*muksevt.Event, error)

func (*HistoryManager) Close

func (hm *HistoryManager) Close() error

func (*HistoryManager) Get

func (hm *HistoryManager) Get(room *rooms.Room, eventID id.EventID) (evt *muksevt.Event, err error)

func (*HistoryManager) Load

func (hm *HistoryManager) Load(room *rooms.Room, num int, ptrStart uint64) (events []*muksevt.Event, newPtrStart uint64, err error)

func (*HistoryManager) Prepend

func (hm *HistoryManager) Prepend(room *rooms.Room, events []*event.Event) ([]*muksevt.Event, uint64, error)

func (*HistoryManager) Update

func (hm *HistoryManager) Update(room *rooms.Room, eventID id.EventID, update func(evt *muksevt.Event) error) error

type StubSyncingModal

type StubSyncingModal struct{}

func (StubSyncingModal) Close

func (s StubSyncingModal) Close()

func (StubSyncingModal) SetIndeterminate

func (s StubSyncingModal) SetIndeterminate()

func (StubSyncingModal) SetMessage

func (s StubSyncingModal) SetMessage(s2 string)

func (StubSyncingModal) SetSteps

func (s StubSyncingModal) SetSteps(i int)

func (StubSyncingModal) Step

func (s StubSyncingModal) Step()

Directories

Path Synopsis
Package rooms contains a representation for Matrix rooms and utilities to parse state events.
Package rooms contains a representation for Matrix rooms and utilities to parse state events.

Jump to

Keyboard shortcuts

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