mxclient

package
v0.0.0-...-aa867a8 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const RoomInitialSyncLimit = 256

Variables

This section is empty.

Functions

func ReverseEventsCopy

func ReverseEventsCopy(events []gomatrix.Event) []gomatrix.Event

ReverseEventsCopy returns a copy of the input slice with all elements in reverse order.

func ShouldHideEvent

func ShouldHideEvent(ev gomatrix.Event) bool

ShouldHideEvent returns a bool the event should be ignored in the timeline view, mimicking riot-web

func TextForRespError

func TextForRespError(respErr gomatrix.RespError) string

TextForRespError returns a string representation of the RespError if known, defaulting to the Err field of the RespError.

func UnwrapRespError

func UnwrapRespError(err error) (respErr gomatrix.RespError, respErrOk bool)

UnwrapRespError takes an error and if it is a HTTPError returns the WrappedError.RespError it contains

Types

type Client

type Client struct {
	*gomatrix.Client
	MediaBaseURL string
}

Our Client extension adds some methods and a field expanding an MXC URL

func NewClient

func NewClient(configPath string) (*Client, error)

NewClient returns a Client configured by the config file found at configPath or an error if encountered.

func NewRawClient

func NewRawClient(homeserverURL, mediaBaseURL, userID, accessToken string) (*Client, error)

NewRawClient returns a wrapped client with http client timeouts applied.

func (*Client) GetRoomDirectoryAlias

func (m *Client) GetRoomDirectoryAlias(roomAlias string) (resp *RespRoomDirectoryAlias, err error)

func (*Client) NewRoom

func (m *Client) NewRoom(roomID string) (*Room, error)

NewRoom fetches :roomId/initialSync for a room and instantiates a room to represent it.

func (*Client) NewWorldReadableRooms

func (m *Client) NewWorldReadableRooms() *WorldReadableRooms

NewWorldReadableRooms instantiates a WorldReadableRooms Collection

func (*Client) RoomInitialSync

func (m *Client) RoomInitialSync(roomID string, limit int) (resp *RespInitialSync, err error)

Register makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-initialsync

type Config

type Config 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"`
	MediaBaseUrl string `json:"media_base_url"`
}

The struct representing the json config file format.

type MXCURL

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

func NewMXCURL

func NewMXCURL(url string, baseUrl string) *MXCURL

NewMXCURL constructs an MXCURL based on the mxc and the baseUrl to any Homeserver which can access the MXCURL.

func (*MXCURL) IsValid

func (m *MXCURL) IsValid() bool

IsValid returns a boolean of whether or not this MXCURL appears valid.

func (*MXCURL) ToThumbURL

func (m *MXCURL) ToThumbURL(width, height int, method string) string

ToThumbUrl returns a http/s URL string representation of the MXCURL at the width&height specified.

func (*MXCURL) ToURL

func (m *MXCURL) ToURL() string

ToThumbUrl returns a http/s URL string representation of the original file uploaded at the MXCURL.s

type MemberInfo

type MemberInfo struct {
	MXID        string
	Membership  string
	DisplayName string
	AvatarURL   MXCURL
	PowerLevel  PowerLevel
}

func NewMemberInfo

func NewMemberInfo(mxid string) *MemberInfo

NewMemberInfo returns a new MemberInfo with defaults (membership=leave) applied.

func (MemberInfo) GetName

func (memberInfo MemberInfo) GetName() string

GetName returns either the user's DisplayName, or if empty, their MXID. TODO make this disambiguate users if their DisplayName is not unique, implementation tips say to make a map of DisplayNames (or Set?) -> MXID?

type MemberList

type MemberList []*MemberInfo

implements sort.Interface

func (MemberList) Len

func (ml MemberList) Len() int

func (MemberList) Less

func (ml MemberList) Less(i, j int) bool

func (MemberList) Swap

func (ml MemberList) Swap(i, j int)

type PowerLevel

type PowerLevel int

func (PowerLevel) Int

func (powerLevel PowerLevel) Int() int

Int allows a quick denature of PowerLevel to an int

func (PowerLevel) String

func (powerLevel PowerLevel) String() string

String is the Stringer implementation for PowerLevel

type PowerLevels

type PowerLevels struct {
	Ban           PowerLevel            `json:"ban"`
	Events        map[string]PowerLevel `json:"events"`
	EventsDefault PowerLevel            `json:"events_default"`
	Invite        PowerLevel            `json:"invite"`
	Kick          PowerLevel            `json:"kick"`
	Redact        PowerLevel            `json:"redact"`
	StateDefault  PowerLevel            `json:"state_default"`
	Users         map[string]PowerLevel `json:"users"`
	UsersDefault  PowerLevel            `json:"users_default"`
}

type RespInitialSync

type RespInitialSync struct {
	Messages gomatrix.RespMessages `json:"messages"`
	// Membership string                 `json:"membership"`
	State []gomatrix.Event `json:"state"`
}

This is a Truncated RespInitialSync as we only need SOME information from it.

type RespRoomDirectoryAlias

type RespRoomDirectoryAlias struct {
	RoomID  string   `json:"room_id"`
	Servers []string `json:"servers"`
}

type Room

type Room struct {
	// each room has a Client that is responsible for its state being up to date
	Client *Client

	ID string

	HasReachedHistoricEndOfTimeline bool

	LastAccess time.Time
	// contains filtered or unexported fields
}

func (*Room) Access

func (r *Room) Access()

func (*Room) ForwardPaginateRoom

func (r *Room) ForwardPaginateRoom()

ForwardPaginateRoom queries the API for any events newer than the latest one currently in the timeline and appends them.

func (*Room) GetEventPage

func (r *Room) GetEventPage(anchor string, offset int, pageSize int) (events []gomatrix.Event, atTopEnd, atBottomEnd bool, err error)

GetEventPage returns a paginated slice of events, as well as whether this slice rests at either/both ends of the timeline.

func (*Room) GetState

func (r *Room) GetState() RoomState

GetState returns an instance of RoomState believed to represent the current state of the room.

func (*Room) RoomInfo

func (r *Room) RoomInfo() RoomInfo

RoomInfo summates basic currentState parameters

type RoomAliases

type RoomAliases []RoomServerAliases

implements sort.Interface

func (RoomAliases) Len

func (p RoomAliases) Len() int

func (RoomAliases) Less

func (p RoomAliases) Less(i, j int) bool

func (RoomAliases) Swap

func (p RoomAliases) Swap(i, j int)

type RoomInfo

type RoomInfo struct {
	RoomID          string
	Name            string
	CanonicalAlias  string
	Topic           string
	RoomVersion     string
	AvatarURL       MXCURL
	NumMemberEvents int
	NumMembers      int
	NumServers      int
}

type RoomServerAliases

type RoomServerAliases struct {
	ServerName string
	Aliases    []string
}

type RoomState

type RoomState struct {
	Creator string
	Topic   string
	Name    string

	AvatarURL MXCURL

	Aliases RoomAliases

	PowerLevels PowerLevels

	MemberMap map[string]*MemberInfo
	// contains filtered or unexported fields
}

func NewRoomState

func NewRoomState(client *Client) *RoomState

NewRoomState creates a RoomState with defaults applied.

func (RoomState) CalculateName

func (rs RoomState) CalculateName() string

Partial implementation of http://matrix.org/docs/spec/client_server/r0.2.0.html#calculating-the-display-name-for-a-room Does not handle based on members if there is no Name/Alias (yet)

func (*RoomState) GetNumMemberEvents

func (rs *RoomState) GetNumMemberEvents() int

GetNumMemberEvents returns the total number of member events found in room state (i.e total number of unique users)

func (RoomState) Members

func (rs RoomState) Members() []*MemberInfo

Members is an accessor for RoomState.memberList

func (RoomState) NumMembers

func (rs RoomState) NumMembers() int

NumMembers returns the number of members with membership=join

func (*RoomState) RecalculateMemberListAndServers

func (rs *RoomState) RecalculateMemberListAndServers()

RecalculateMemberListAndServers does member list calculation, sorting and server calculations. ideally called at the end of concatenating so that its done as infrequently as possible whilst still never causing outdated information.

func (RoomState) Servers

func (rs RoomState) Servers() []ServerUserCount

Servers iterates over the Member List (membership=join), splits each MXID and counts the number of each homeserver url.

func (*RoomState) UpdateOnEvent

func (rs *RoomState) UpdateOnEvent(event *gomatrix.Event, usePrevContent bool)

UpdateOnEvent iterates the Room State based on the event observed.

type ServerUserCount

type ServerUserCount struct {
	ServerName string
	NumUsers   int
}

type ServerUserCounts

type ServerUserCounts []ServerUserCount

implements sort.Interface

func (ServerUserCounts) Len

func (p ServerUserCounts) Len() int

func (ServerUserCounts) Less

func (p ServerUserCounts) Less(i, j int) bool

func (ServerUserCounts) Swap

func (p ServerUserCounts) Swap(i, j int)

type WorldReadableRooms

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

func (*WorldReadableRooms) GetFilteredPage

func (r *WorldReadableRooms) GetFilteredPage(page, pageSize int, query string) []gomatrix.PublicRoom

GetFilteredPage returns a filtered & paginated slice of the WorldReadableRooms Collection

func (*WorldReadableRooms) GetPage

func (r *WorldReadableRooms) GetPage(page, pageSize int) []gomatrix.PublicRoom

GetPage returns a paginated slice of the WorldReadableRooms Collection

func (*WorldReadableRooms) Update

func (r *WorldReadableRooms) Update() error

Update updates the state of the WorldReadableRooms Collection by doing an API Call.

Jump to

Keyboard shortcuts

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