section

package
v0.1.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	InternalTagNamespace = "xyz.diamondb.gotktrix"

	DMSection    matrix.TagName = InternalTagNamespace + ".dm_section"
	RoomsSection matrix.TagName = InternalTagNamespace + ".rooms_section"
)

Pseudo tag names.

Variables

View Source
var MatrixSectionOrder = map[matrix.TagName]int{
	matrix.TagFavourite:    0,
	DMSection:              1,
	RoomsSection:           2,
	matrix.TagLowPriority:  3,
	matrix.TagServerNotice: 4,
}

MatrixSectionOrder is the order of default Matrix rooms.

Functions

func RoomTag

func RoomTag(c *gotktrix.Client, id matrix.RoomID) matrix.TagName

RoomTag queries the client and returns the tag that the room with the given ID is in. It tries its best to be deterministic. If the room should be in the default room section, then an empty string is returned.

func SortSections

func SortSections(sections []*Section)

SortSections sorts the given list of sections in a user-friendly way.

func SortTags

func SortTags(tags []OrderedTag)

SortTags sorts the given list of ordered tags in a deterministic order.

func TagEqNamespace

func TagEqNamespace(n1, n2 matrix.TagName) bool

TagEqNamespace returns true if n1 and n2 are in the same namespace.

func TagIsIntern

func TagIsIntern(name matrix.TagName) bool

TagIsIntern returns true if the given tag is a Matrix tag or a tag that belongs only to us.

func TagName

func TagName(ctx context.Context, name matrix.TagName) string

TagName returns the name of the given tag.

func TagNamespace

func TagNamespace(name matrix.TagName) string

TagNamespace returns the tag's namespace.

Types

type Comparer

type Comparer struct {
	// Tag is the tag that this comparer should use. If this is an empty string,
	// then Comparer will ignore room tags completely.
	Tag matrix.TagName
	// Mode is the sorting mode that this comparer should do.
	Mode SortMode
	// contains filtered or unexported fields
}

Comparer partially implements sort.Interface: it provides a Less function that Sorter can easily build upon, but exposed for other uses.

func NewComparer

func NewComparer(client *gotktrix.Client, mode SortMode, tag matrix.TagName) *Comparer

NewComparer creates a new comparer.

func (*Comparer) Compare

func (c *Comparer) Compare(iID, jID matrix.RoomID) int

Compare behaves similarly to strings.Compare. Most users should use Less instead of Compare; this method only exists to satisfy bad C APIs.

As the API is similar to strings.Compare, 0 is returned if the position is equal; -1 is returned if iID's position is less than (above/before) jID, and 1 is returned if iID's position is more than (below/after) jID.

func (*Comparer) InvalidateRoomCache

func (c *Comparer) InvalidateRoomCache()

InvalidateRoomCache invalidates the room name/timestamp cache. This is automatically called when Sort is called.

func (*Comparer) Less

func (c *Comparer) Less(iID, jID matrix.RoomID) bool

Less returns true if the room with iID should be before the one with jID.

type Controller

type Controller interface {
	OpenRoom(matrix.RoomID)
	OpenRoomInTab(matrix.RoomID)

	// RoomIsVisible returns true if the given room should be visible.
	RoomIsVisible(matrix.RoomID) bool
	// IsSearching returns true if the user is searching for any room. This will
	// cause the section to not collapse.
	IsSearching() bool

	// VAdjustment returns the vertical scroll adjustment of the parent
	// controller. If not in list, return nil.
	VAdjustment() *gtk.Adjustment

	// MoveRoomToSection moves a room to another section. The method is expected
	// to verify that the moving is valid.
	MoveRoomToSection(src matrix.RoomID, dst *Section) bool
	// MoveRoomToTag moves the room with the given ID to the given tag name. A
	// new section must be created if needed.
	MoveRoomToTag(src matrix.RoomID, tag matrix.TagName) bool
}

Controller describes the parent widget that Section controls.

type OrderedTag

type OrderedTag struct {
	Name  matrix.TagName
	Order float64 // 2 if nil
}

OrderedTag is a type that defines the tag order. It is used for sorting and prioritizing room tags.

func NewOrderedTags

func NewOrderedTags(tags map[matrix.TagName]matrix.Tag) []OrderedTag

NewOrderedTags creates a new list of

func RoomTags

func RoomTags(c *gotktrix.Client, id matrix.RoomID) []OrderedTag

RoomTags returns the tags of the given room sorted in a deterministic order.

type Section

type Section struct {
	*gtk.Box
	// contains filtered or unexported fields
}

Section is a room section, such as People or Favorites.

func New

func New(ctx context.Context, ctrl Controller, tag matrix.TagName) *Section

New creates a new deactivated section.

func (*Section) Changed

func (s *Section) Changed(room *room.Room)

Changed reorders the given room specifically.

func (*Section) Expand

func (s *Section) Expand()

Expand makes the section display all rooms inside it.

func (*Section) HasRoom

func (s *Section) HasRoom(id matrix.RoomID) bool

HasRoom returns true if the section contains the given room.

func (*Section) Insert

func (s *Section) Insert(room *room.Room)

Insert adds a room.

func (*Section) InvalidateFilter

func (s *Section) InvalidateFilter()

InvalidateFilter invalidates the filter.

func (*Section) InvalidateSort

func (s *Section) InvalidateSort()

InvalidateSort invalidates the section's sort. This should be called if any room inside the section has been changed.

func (*Section) Minimize

func (s *Section) Minimize()

Minimize minimizes the section to only show 8 entries.

func (*Section) MoveRoomToTag

func (s *Section) MoveRoomToTag(src matrix.RoomID, tag matrix.TagName) bool

MoveRoomToTag calls the parent controller's.

func (*Section) NHidden

func (s *Section) NHidden() int

NHidden returns the number of hidden rooms.

func (*Section) OpenRoom

func (s *Section) OpenRoom(id matrix.RoomID)

OpenRoom calls the parent controller's.

func (*Section) OpenRoomInTab

func (s *Section) OpenRoomInTab(id matrix.RoomID)

OpenRoomInTab calls the parent controller's.

func (*Section) Reminify

func (s *Section) Reminify()

Reminify restores the minified state.

func (*Section) ReminifyAfter

func (s *Section) ReminifyAfter(after func())

ReminifyAfter restores the minified state only after executing after. If the section is not minified, then after is executed immediately. If after is nil, then it does the same thing as Reminify does.

func (*Section) Remove

func (s *Section) Remove(room *room.Room)

Remove removes the given room from the list.

func (*Section) Select

func (s *Section) Select(id matrix.RoomID)

Select selects the room with the given ID. If an unknown ID is given, then the function panics.

func (*Section) SetSortMode

func (s *Section) SetSortMode(mode SortMode)

SetSortMode sets the sorting mode for each room.

func (*Section) SortMode

func (s *Section) SortMode() SortMode

SortMode returns the section's current sort mode.

func (*Section) Tag

func (s *Section) Tag() matrix.TagName

Tag returns the tag name of this section.

func (*Section) Unselect

func (s *Section) Unselect()

Unselect unselects the list of the current section.

type SortMode

type SortMode uint8

SortMode describes the possible ways to sort a room.

const (
	SortName SortMode = iota // A-Z
	SortActivity
)

Jump to

Keyboard shortcuts

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