database

package
v0.2608.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: AGPL-3.0, MPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const MaxMediaBackoff = 7 * 24 * time.Hour
View Source
const PrevBatchPaginationComplete = "fi.mau.gomuks.pagination_complete"

Variables

This section is empty.

Functions

func GetRelatesToFromBytes

func GetRelatesToFromBytes(content []byte) (id.EventID, event.RelationType)

Types

type Account

type Account struct {
	UserID        id.UserID   `json:"user_id,omitempty"`
	DeviceID      id.DeviceID `json:"device_id,omitempty"`
	AccessToken   string      `json:"access_token,omitempty"`
	HomeserverURL string      `json:"homeserver_url,omitempty"`
	NextBatch     string      `json:"-"`

	ClientID     string             `json:"client_id,omitempty"`
	RefreshToken string             `json:"refresh_token,omitempty"`
	Expiry       jsontime.UnixMilli `json:"expiry,omitzero"`

	DisplayName string        `json:"display_name,omitempty"`
	AvatarURL   id.ContentURI `json:"avatar_url,omitempty"`
}

func (*Account) Scan

func (a *Account) Scan(row dbutil.Scannable) (*Account, error)

type AccountData

type AccountData struct {
	// The user ID who owns this account data (i.e. always the currently logged-in user).
	UserID id.UserID `json:"user_id"`
	// If this is a room account data event, the room ID it is associated with. Omitted for global account data.
	RoomID id.RoomID `json:"room_id,omitempty"`

	Type    string          `json:"type"`
	Content json.RawMessage `json:"content"`
}

func (*AccountData) Scan

func (a *AccountData) Scan(row dbutil.Scannable) (*AccountData, error)

type AccountDataQuery

type AccountDataQuery struct {
	*dbutil.QueryHelper[*AccountData]
}

func (*AccountDataQuery) GetAllGlobal

func (adq *AccountDataQuery) GetAllGlobal(ctx context.Context, userID id.UserID) ([]*AccountData, error)

func (*AccountDataQuery) GetAllGlobalSince added in v0.2608.0

func (adq *AccountDataQuery) GetAllGlobalSince(ctx context.Context, userID id.UserID, updatedAfter int64) ([]*AccountData, error)

func (*AccountDataQuery) GetAllRoom

func (adq *AccountDataQuery) GetAllRoom(ctx context.Context, userID id.UserID, roomID id.RoomID) ([]*AccountData, error)

func (*AccountDataQuery) GetAllRoomSince added in v0.2608.0

func (adq *AccountDataQuery) GetAllRoomSince(ctx context.Context, userID id.UserID, updatedAfter int64) ([]*AccountData, error)

func (*AccountDataQuery) GetGlobal added in v0.2603.0

func (adq *AccountDataQuery) GetGlobal(ctx context.Context, userID id.UserID, eventType event.Type) (*AccountData, error)

func (*AccountDataQuery) GetRoom added in v0.2603.0

func (adq *AccountDataQuery) GetRoom(ctx context.Context, userID id.UserID, roomID id.RoomID, eventType event.Type) (*AccountData, error)

func (*AccountDataQuery) Put

func (adq *AccountDataQuery) Put(ctx context.Context, userID id.UserID, eventType event.Type, content json.RawMessage) (*AccountData, error)

func (*AccountDataQuery) PutRoom

func (adq *AccountDataQuery) PutRoom(ctx context.Context, userID id.UserID, roomID id.RoomID, eventType event.Type, content json.RawMessage) (*AccountData, error)

type AccountQuery

type AccountQuery struct {
	*dbutil.QueryHelper[*Account]
}

func (*AccountQuery) Get

func (aq *AccountQuery) Get(ctx context.Context, userID id.UserID) (*Account, error)

func (*AccountQuery) GetFirstUserID

func (aq *AccountQuery) GetFirstUserID(ctx context.Context) (userID id.UserID, err error)

func (*AccountQuery) Put

func (aq *AccountQuery) Put(ctx context.Context, account *Account) error

func (*AccountQuery) PutNextBatch

func (aq *AccountQuery) PutNextBatch(ctx context.Context, userID id.UserID, nextBatch string) error

func (*AccountQuery) PutProfile added in v0.2607.0

func (aq *AccountQuery) PutProfile(ctx context.Context, userID id.UserID, displayname string, avatarURL id.ContentURI) error

func (*AccountQuery) PutRefreshToken added in v0.2607.0

func (aq *AccountQuery) PutRefreshToken(ctx context.Context, userID id.UserID, refreshToken, accessToken string, expiry time.Time) error

type ClientStateStore

type ClientStateStore struct {
	*Database
}

func (*ClientStateStore) ClearCachedMembers

func (c *ClientStateStore) ClearCachedMembers(ctx context.Context, roomID id.RoomID, memberships ...event.Membership) error

func (*ClientStateStore) FindSharedRooms

func (c *ClientStateStore) FindSharedRooms(ctx context.Context, userID id.UserID) ([]id.RoomID, error)

func (*ClientStateStore) GetAllMembers

func (c *ClientStateStore) GetAllMembers(ctx context.Context, roomID id.RoomID) (map[id.UserID]*event.MemberEventContent, error)

func (*ClientStateStore) GetCreate

func (c *ClientStateStore) GetCreate(ctx context.Context, roomID id.RoomID) (*event.Event, error)

func (*ClientStateStore) GetEncryptionEvent

func (c *ClientStateStore) GetEncryptionEvent(ctx context.Context, roomID id.RoomID) (content *event.EncryptionEventContent, err error)

func (*ClientStateStore) GetHistoryVisibility added in v0.2608.0

func (c *ClientStateStore) GetHistoryVisibility(ctx context.Context, roomID id.RoomID) (content *event.HistoryVisibilityEventContent, err error)

func (*ClientStateStore) GetJoinRules

func (c *ClientStateStore) GetJoinRules(ctx context.Context, roomID id.RoomID) (content *event.JoinRulesEventContent, err error)

func (*ClientStateStore) GetMember

func (c *ClientStateStore) GetMember(ctx context.Context, roomID id.RoomID, userID id.UserID) (*event.MemberEventContent, error)

func (*ClientStateStore) GetPowerLevels

func (c *ClientStateStore) GetPowerLevels(ctx context.Context, roomID id.RoomID) (content *event.PowerLevelsEventContent, err error)

func (*ClientStateStore) GetRoomJoinedMembers

func (c *ClientStateStore) GetRoomJoinedMembers(ctx context.Context, roomID id.RoomID) ([]id.UserID, error)

func (*ClientStateStore) GetRoomJoinedOrInvitedMembers

func (c *ClientStateStore) GetRoomJoinedOrInvitedMembers(ctx context.Context, roomID id.RoomID) ([]id.UserID, error)

func (*ClientStateStore) HasFetchedMembers

func (c *ClientStateStore) HasFetchedMembers(ctx context.Context, roomID id.RoomID) (hasFetched bool, err error)

func (*ClientStateStore) IsConfusableName

func (c *ClientStateStore) IsConfusableName(ctx context.Context, roomID id.RoomID, currentUser id.UserID, name string) ([]id.UserID, error)

func (*ClientStateStore) IsEncrypted

func (c *ClientStateStore) IsEncrypted(ctx context.Context, roomID id.RoomID) (isEncrypted bool, err error)

func (*ClientStateStore) IsInRoom

func (c *ClientStateStore) IsInRoom(ctx context.Context, roomID id.RoomID, userID id.UserID) bool

func (*ClientStateStore) IsInvited

func (c *ClientStateStore) IsInvited(ctx context.Context, roomID id.RoomID, userID id.UserID) bool

func (*ClientStateStore) IsMembership

func (c *ClientStateStore) IsMembership(ctx context.Context, roomID id.RoomID, userID id.UserID, allowedMemberships ...event.Membership) bool

func (*ClientStateStore) MarkMembersFetched

func (c *ClientStateStore) MarkMembersFetched(ctx context.Context, roomID id.RoomID) error

func (*ClientStateStore) ReplaceCachedMembers

func (c *ClientStateStore) ReplaceCachedMembers(ctx context.Context, roomID id.RoomID, evts []*event.Event, onlyMemberships ...event.Membership) error

func (*ClientStateStore) SetCreate

func (c *ClientStateStore) SetCreate(ctx context.Context, evt *event.Event) error

func (*ClientStateStore) SetEncryptionEvent

func (c *ClientStateStore) SetEncryptionEvent(ctx context.Context, roomID id.RoomID, content *event.EncryptionEventContent) error

func (*ClientStateStore) SetHistoryVisibility added in v0.2608.0

func (c *ClientStateStore) SetHistoryVisibility(ctx context.Context, roomID id.RoomID, content *event.HistoryVisibilityEventContent) error

func (*ClientStateStore) SetJoinRules

func (c *ClientStateStore) SetJoinRules(ctx context.Context, roomID id.RoomID, content *event.JoinRulesEventContent) error

func (*ClientStateStore) SetMember

func (c *ClientStateStore) SetMember(ctx context.Context, roomID id.RoomID, userID id.UserID, member *event.MemberEventContent) error

func (*ClientStateStore) SetMembership

func (c *ClientStateStore) SetMembership(ctx context.Context, roomID id.RoomID, userID id.UserID, membership event.Membership) error

func (*ClientStateStore) SetPowerLevels

func (c *ClientStateStore) SetPowerLevels(ctx context.Context, roomID id.RoomID, levels *event.PowerLevelsEventContent) error

func (*ClientStateStore) TryGetMember

func (c *ClientStateStore) TryGetMember(ctx context.Context, roomID id.RoomID, userID id.UserID) (content *event.MemberEventContent, err error)

func (*ClientStateStore) UpdateState

func (c *ClientStateStore) UpdateState(ctx context.Context, evt *event.Event)

type CurrentStateEntry

type CurrentStateEntry struct {
	EventType  event.Type
	StateKey   string
	EventRowID EventRowID
	Membership event.Membership
}

func (*CurrentStateEntry) GetMassInsertValues

func (cse *CurrentStateEntry) GetMassInsertValues() [4]any

type CurrentStateQuery

type CurrentStateQuery struct {
	*dbutil.QueryHelper[*Event]
}

func (*CurrentStateQuery) Add

func (csq *CurrentStateQuery) Add(ctx context.Context, roomID id.RoomID, eventType event.Type, stateKey string, eventRowID EventRowID, membership event.Membership) error

func (*CurrentStateQuery) AddMany

func (csq *CurrentStateQuery) AddMany(ctx context.Context, roomID id.RoomID, deleteOld bool, entries []*CurrentStateEntry) error

func (*CurrentStateQuery) Get

func (csq *CurrentStateQuery) Get(ctx context.Context, roomID id.RoomID, eventType event.Type, stateKey string) (*Event, error)

func (*CurrentStateQuery) GetAll

func (csq *CurrentStateQuery) GetAll(ctx context.Context, roomID id.RoomID) ([]*Event, error)

func (*CurrentStateQuery) GetAllExceptMembers

func (csq *CurrentStateQuery) GetAllExceptMembers(ctx context.Context, roomID id.RoomID) ([]*Event, error)

func (*CurrentStateQuery) GetMany

func (csq *CurrentStateQuery) GetMany(ctx context.Context, keys []RoomStateGUID) ([]*Event, error)

func (*CurrentStateQuery) GetMembers

func (csq *CurrentStateQuery) GetMembers(ctx context.Context, roomID id.RoomID) ([]*Event, error)

func (*CurrentStateQuery) Set

func (csq *CurrentStateQuery) Set(ctx context.Context, roomID id.RoomID, eventType event.Type, stateKey string, eventRowID EventRowID, membership event.Membership) error

type Database

type Database struct {
	*dbutil.Database

	Account          *AccountQuery
	AccountData      *AccountDataQuery
	Room             *RoomQuery
	InvitedRoom      *InvitedRoomQuery
	Event            *EventQuery
	CurrentState     *CurrentStateQuery
	Timeline         *TimelineQuery
	SessionRequest   *SessionRequestQuery
	Receipt          *ReceiptQuery
	Media            *MediaQuery
	SpaceEdge        *SpaceEdgeQuery
	PushRegistration *PushRegistrationQuery
}

func New

func New(rawDB *dbutil.Database) *Database

type EncryptionKey

type EncryptionKey struct {
	// 32 random bytes used as the static AES-GCM key.
	Key []byte `json:"key,omitempty"`
}

type Event

type Event struct {
	RowID EventRowID `json:"rowid"`
	// The timeline row ID is only filled when paginating messages.
	// In normal syncs, timeline row IDs can be found in the separate `timeline` field rather than inside events.
	TimelineRowID TimelineRowID `json:"timeline_rowid"`

	RoomID    id.RoomID          `json:"room_id"`
	ID        id.EventID         `json:"event_id"`
	Sender    id.UserID          `json:"sender"`
	Type      string             `json:"type"`
	StateKey  *string            `json:"state_key,omitempty"`
	Timestamp jsontime.UnixMilli `json:"timestamp"`

	Content       json.RawMessage `json:"content"`
	Decrypted     json.RawMessage `json:"decrypted,omitempty"`
	DecryptedType string          `json:"decrypted_type,omitempty"`
	Unsigned      json.RawMessage `json:"unsigned,omitempty"`
	LocalContent  *LocalContent   `json:"local_content,omitempty"`

	TransactionID string `json:"transaction_id,omitempty"`

	RedactedBy   id.EventID         `json:"redacted_by,omitempty"`
	RelatesTo    id.EventID         `json:"relates_to,omitempty"`
	RelationType event.RelationType `json:"relation_type,omitempty"`

	MegolmSessionID id.SessionID `json:"-"`
	DecryptionError string       `json:"decryption_error,omitempty"`
	SendError       string       `json:"send_error,omitempty"`

	Reactions     map[string]int `json:"reactions,omitempty"`
	LastEditRowID *EventRowID    `json:"last_edit_rowid,omitempty"`
	UnreadType    UnreadType     `json:"unread_type,omitempty"`

	StickyDuration jsontime.Milliseconds `json:"sticky_duration_ms,omitzero"`

	LastEditRef *Event `json:"-"`
	Pending     bool   `json:"-"`
	RenderMeta  any    `json:"-"`
	// contains filtered or unexported fields
}

Event represents a single Matrix room event.

func MakeFakeEvent added in v0.2601.0

func MakeFakeEvent(roomID id.RoomID, html string) *Event

func MautrixToEvent

func MautrixToEvent(evt *event.Event) *Event

func (*Event) AsMautrix

func (e *Event) AsMautrix() *event.Event

func (*Event) AsRawMautrix

func (e *Event) AsRawMautrix() *event.Event

func (*Event) BumpsSortingTimestamp

func (e *Event) BumpsSortingTimestamp() bool

func (*Event) CanUseForPreview

func (e *Event) CanUseForPreview() bool

func (*Event) GetContent

func (e *Event) GetContent() json.RawMessage

func (*Event) GetLocalContent

func (e *Event) GetLocalContent() *LocalContent

func (*Event) GetMassInsertValues

func (e *Event) GetMassInsertValues() [9]any

func (*Event) GetMautrixContent

func (e *Event) GetMautrixContent() *event.Content

func (*Event) GetNonPushUnreadType

func (e *Event) GetNonPushUnreadType() UnreadType

func (*Event) GetReplyTo

func (e *Event) GetReplyTo() id.EventID

func (*Event) GetType

func (e *Event) GetType() (evtType event.Type)

func (*Event) MarkReplyFallbackRemoved

func (e *Event) MarkReplyFallbackRemoved()

func (*Event) Scan

func (e *Event) Scan(row dbutil.Scannable) (*Event, error)

type EventQuery

type EventQuery struct {
	*dbutil.QueryHelper[*Event]
}

func (*EventQuery) FillLastEditRowIDs

func (eq *EventQuery) FillLastEditRowIDs(ctx context.Context, roomID id.RoomID, events []*Event) error

func (*EventQuery) FillReactionCounts

func (eq *EventQuery) FillReactionCounts(ctx context.Context, roomID id.RoomID, events []*Event) error

func (*EventQuery) GetActiveSticky added in v0.2604.0

func (eq *EventQuery) GetActiveSticky(ctx context.Context, roomID id.RoomID) ([]*Event, error)

func (*EventQuery) GetByID

func (eq *EventQuery) GetByID(ctx context.Context, roomID id.RoomID, eventID id.EventID) (*Event, error)

func (*EventQuery) GetByRowID

func (eq *EventQuery) GetByRowID(ctx context.Context, rowID EventRowID) (*Event, error)

func (*EventQuery) GetByRowIDs

func (eq *EventQuery) GetByRowIDs(ctx context.Context, rowIDs ...EventRowID) ([]*Event, error)

func (*EventQuery) GetByTransactionID

func (eq *EventQuery) GetByTransactionID(ctx context.Context, txnID string) (*Event, error)

func (*EventQuery) GetEditRowIDs

func (eq *EventQuery) GetEditRowIDs(ctx context.Context, roomID id.RoomID, eventIDs ...id.EventID) (map[id.EventID][]EventRowID, error)

func (*EventQuery) GetFailedByMegolmSessionID

func (eq *EventQuery) GetFailedByMegolmSessionID(ctx context.Context, roomID id.RoomID, sessionID id.SessionID) ([]*Event, error)

func (*EventQuery) GetMentions added in v0.2601.0

func (eq *EventQuery) GetMentions(ctx context.Context, ts time.Time, unreadType UnreadType, limit int, roomID id.RoomID) ([]*Event, error)

func (*EventQuery) GetReactions

func (eq *EventQuery) GetReactions(ctx context.Context, roomID id.RoomID, eventIDs ...id.EventID) (map[id.EventID]*GetReactionsResult, error)

func (*EventQuery) GetRelatedEvents

func (eq *EventQuery) GetRelatedEvents(ctx context.Context, roomID id.RoomID, eventID id.EventID, relationType event.RelationType, eventType string) ([]*Event, error)

func (*EventQuery) Insert

func (eq *EventQuery) Insert(ctx context.Context, evt *Event) (rowID EventRowID, err error)

func (*EventQuery) MassUpsertState

func (eq *EventQuery) MassUpsertState(ctx context.Context, evts []*Event) error

func (*EventQuery) Search added in v0.2606.0

func (eq *EventQuery) Search(
	ctx context.Context,
	matches, like string,
	rooms []id.RoomID,
	senders []id.UserID,
	minTime, maxTime time.Time,
	includeRedacted bool,
	orderByTimeOnly bool,
	limit, offset int,
) ([]*Event, error)

func (*EventQuery) UpdateDecrypted

func (eq *EventQuery) UpdateDecrypted(ctx context.Context, evt *Event) error

func (*EventQuery) UpdateEncryptedContent

func (eq *EventQuery) UpdateEncryptedContent(ctx context.Context, evt *Event) error

func (*EventQuery) UpdateID

func (eq *EventQuery) UpdateID(ctx context.Context, rowID EventRowID, newID id.EventID) error

func (*EventQuery) UpdateLocalContent

func (eq *EventQuery) UpdateLocalContent(ctx context.Context, evt *Event) error

func (*EventQuery) UpdateSendError

func (eq *EventQuery) UpdateSendError(ctx context.Context, rowID EventRowID, sendError string) error

func (*EventQuery) Upsert

func (eq *EventQuery) Upsert(ctx context.Context, evt *Event) (rowID EventRowID, err error)

type EventRowID

type EventRowID int64

An EventRowID uniquely identifies a single Matrix room event in the gomuks database.

Event row IDs are always positive integers. They are not ordered in any useful way, the counter is simply incremented whenever a new event is persisted. Paginating up in history will cause old events to be added after new ones for example.

func (EventRowID) GetMassInsertValues

func (m EventRowID) GetMassInsertValues() [1]any

type GetReactionsResult

type GetReactionsResult struct {
	Events []*Event
	Counts map[string]int
}

type InvitedRoom

type InvitedRoom struct {
	// The ID of the invited room.
	ID id.RoomID `json:"room_id"`
	// Either the timestamp of the invite event, or the time when the invite was received.
	CreatedAt jsontime.UnixMilli `json:"created_at"`
	// The (untrusted) room metadata state events for the room.
	InviteState []*event.Event `json:"invite_state"`
}

func (*InvitedRoom) GetDMUserID added in v0.2603.0

func (r *InvitedRoom) GetDMUserID(self id.UserID) (target id.UserID)

func (*InvitedRoom) Scan

func (r *InvitedRoom) Scan(row dbutil.Scannable) (*InvitedRoom, error)

type InvitedRoomQuery

type InvitedRoomQuery struct {
	*dbutil.QueryHelper[*InvitedRoom]
}

func (*InvitedRoomQuery) Delete

func (irq *InvitedRoomQuery) Delete(ctx context.Context, roomID id.RoomID) error

func (*InvitedRoomQuery) Get added in v0.2603.0

func (irq *InvitedRoomQuery) Get(ctx context.Context, roomID id.RoomID) (*InvitedRoom, error)

func (*InvitedRoomQuery) GetAll

func (irq *InvitedRoomQuery) GetAll(ctx context.Context) ([]*InvitedRoom, error)

func (*InvitedRoomQuery) GetAllSince added in v0.2608.0

func (irq *InvitedRoomQuery) GetAllSince(ctx context.Context, since int64) ([]*InvitedRoom, error)

func (*InvitedRoomQuery) Upsert

func (irq *InvitedRoomQuery) Upsert(ctx context.Context, room *InvitedRoom) error

type LocalContent

type LocalContent struct {
	// Sanitized HTML that is safe to render directly. This is optimized for web browsers,
	// non-web frontends may want to parse the original HTML from `formatted_body` locally.
	SanitizedHTML string `json:"sanitized_html,omitempty"`
	// A version identifier for the sanitized HTML. This is only used to reparse the source
	// in case there are changes to the sanitizer. Not relevant for frontends.
	HTMLVersion int `json:"html_version,omitempty"`
	// Whether the event was plaintext, i.e. did not have a `formatted_body` field.
	// `sanitized_html` may be present anyway in case `body` contained characters that need HTML escaping.
	WasPlaintext bool `json:"was_plaintext,omitempty"`
	// Whether the event contains emoji only and should be rendered with a big font size.
	BigEmoji bool `json:"big_emoji,omitempty"`
	// Whether the event contains LaTeX math.
	HasMath bool `json:"has_math,omitempty"`
	// The message content that should be used as the initial composer state when editing this message.
	// For messages sent from this gomuks instance, this will be the raw user input. For messages sent
	// from other clients, this is parsed from the HTML and therefore may have slight changes to the
	// original markdown (but the resulting HTML is the same anyway).
	EditSource string `json:"edit_source,omitempty"`
	// Whether the reply fallback was removed from the `body` and `formatted_body`.
	// There is no way to get it back, as the content isn't stored.
	ReplyFallbackRemoved bool `json:"reply_fallback_removed,omitempty"`
	// The push rule ID that caused this event to notify or highlight.
	PushRuleID string `json:"push_rule_id,omitempty"`
}

func (*LocalContent) GetPushRuleID added in v0.2602.0

func (c *LocalContent) GetPushRuleID() string

func (*LocalContent) GetReplyFallbackRemoved

func (c *LocalContent) GetReplyFallbackRemoved() bool

type Media

type Media struct {
	MXC      id.ContentURI             `json:"-"`
	EncFile  *attachment.EncryptedFile `json:"-"`
	FileName string                    `json:"file_name"`
	MimeType string                    `json:"mime_type"`
	Size     int64                     `json:"size"`
	Hash     *[32]byte                 `json:"-"`
	Error    *MediaError               `json:"-"`

	ThumbnailError string    `json:"thumbnail_error,omitempty"`
	ThumbnailSize  int64     `json:"thumbnail_size,omitempty"`
	ThumbnailHash  *[32]byte `json:"-"`
}

func (*Media) ContentDisposition

func (m *Media) ContentDisposition() string

func (*Media) ETag

func (m *Media) ETag(thumbnail bool) string

func (*Media) Scan

func (m *Media) Scan(row dbutil.Scannable) (*Media, error)

func (*Media) ToHeaders added in v0.2608.0

func (m *Media) ToHeaders(h http.Header, thumbnail bool)

func (*Media) UseCache

func (m *Media) UseCache() bool

type MediaError

type MediaError struct {
	Matrix     *mautrix.RespError `json:"data"`
	StatusCode int                `json:"status_code"`
	ReceivedAt jsontime.UnixMilli `json:"received_at"`
	Attempts   int                `json:"attempts"`
}

func (*MediaError) AsRespError added in v0.2608.0

func (me *MediaError) AsRespError() mautrix.RespError

func (*MediaError) UseCache

func (me *MediaError) UseCache() bool

func (*MediaError) Write

func (me *MediaError) Write(w http.ResponseWriter)

type MediaQuery

type MediaQuery struct {
	*dbutil.QueryHelper[*Media]
}

func (*MediaQuery) Add

func (mq *MediaQuery) Add(ctx context.Context, cm *Media) error

func (*MediaQuery) AddMany

func (mq *MediaQuery) AddMany(ctx context.Context, medias []*PlainMedia) error

func (*MediaQuery) AddManyReferences

func (mq *MediaQuery) AddManyReferences(ctx context.Context, refs []*MediaReference) error

func (*MediaQuery) AddReference

func (mq *MediaQuery) AddReference(ctx context.Context, evtRowID EventRowID, mxc id.ContentURI) error

func (*MediaQuery) Get

func (mq *MediaQuery) Get(ctx context.Context, mxc id.ContentURI) (*Media, error)

func (*MediaQuery) Put

func (mq *MediaQuery) Put(ctx context.Context, cm *Media) error

type MediaReference

type MediaReference struct {
	EventRowID EventRowID
	MediaMXC   id.ContentURI
}

func (*MediaReference) GetMassInsertValues

func (mr *MediaReference) GetMassInsertValues() [2]any

type NameQuality

type NameQuality int
const (
	NameQualityNil NameQuality = iota
	NameQualityParticipants
	NameQualityCanonicalAlias
	NameQualityExplicit
)

type PlainMedia

type PlainMedia id.ContentURI

func (*PlainMedia) GetMassInsertValues

func (pm *PlainMedia) GetMassInsertValues() [1]any

type PushRegistration

type PushRegistration struct {
	// An arbitrary (but stable) device identifier. Only one push registration can be active per device ID.
	DeviceID string `json:"device_id"`
	// The type of pusher.
	Type PushType `json:"type"`
	// The type-specific data.
	//
	// For FCM, this is the FCM token as a string.
	// For web push, this is the subscription info as a JSON object
	// (`endpoint` string and `keys` object with `p256dh` and `auth` strings).
	Data json.RawMessage `json:"data"`
	// An optional gomuks-specific encryption configuration. Mostly relevant for FCM (and APNs in
	// the future), as web push has built-in encryption.
	Encryption EncryptionKey `json:"encryption"`
	// Unix timestamp (seconds) when the registration should be considered stale.
	// The frontend should re-register well before this time.
	Expiration jsontime.Unix `json:"expiration"`
}

func (*PushRegistration) Scan

type PushRegistrationQuery

type PushRegistrationQuery struct {
	*dbutil.QueryHelper[*PushRegistration]
}

func (*PushRegistrationQuery) GetAll

func (*PushRegistrationQuery) Put

type PushType

type PushType string
const (
	PushTypeFCM PushType = "fcm"
	PushTypeWeb PushType = "web"
)

type Receipt

type Receipt struct {
	RoomID      id.RoomID          `json:"room_id,omitempty"`
	UserID      id.UserID          `json:"user_id"`
	ReceiptType event.ReceiptType  `json:"receipt_type"`
	ThreadID    event.ThreadID     `json:"thread_id,omitempty"`
	EventID     id.EventID         `json:"event_id"`
	Timestamp   jsontime.UnixMilli `json:"timestamp"`
}

func (*Receipt) GetMassInsertValues

func (r *Receipt) GetMassInsertValues() [5]any

func (*Receipt) Scan

func (r *Receipt) Scan(row dbutil.Scannable) (*Receipt, error)

type ReceiptQuery

type ReceiptQuery struct {
	*dbutil.QueryHelper[*Receipt]
}

func (*ReceiptQuery) GetManyRead

func (rq *ReceiptQuery) GetManyRead(ctx context.Context, roomID id.RoomID, eventIDs []id.EventID) (map[id.EventID][]*Receipt, error)

func (*ReceiptQuery) Put

func (rq *ReceiptQuery) Put(ctx context.Context, receipt *Receipt) error

func (*ReceiptQuery) PutMany

func (rq *ReceiptQuery) PutMany(ctx context.Context, roomID id.RoomID, receipts ...*Receipt) error

type Room

type Room struct {
	ID              id.RoomID                    `json:"room_id"`
	CreationContent *event.CreateEventContent    `json:"creation_content,omitempty"`
	Tombstone       *event.TombstoneEventContent `json:"tombstone,omitempty"`

	Name           *string        `json:"name,omitempty"`
	NameQuality    NameQuality    `json:"name_quality"`
	Avatar         *id.ContentURI `json:"avatar,omitempty"`
	ExplicitAvatar bool           `json:"explicit_avatar"`
	DMUserID       *id.UserID     `json:"dm_user_id,omitempty"`
	Topic          *string        `json:"topic,omitempty"`
	CanonicalAlias *id.RoomAlias  `json:"canonical_alias,omitempty"`

	LazyLoadSummary *mautrix.LazyLoadSummary `json:"lazy_load_summary,omitempty"`

	EncryptionEvent *event.EncryptionEventContent `json:"encryption_event,omitempty"`
	HasMemberList   bool                          `json:"has_member_list"`

	PreviewEventRowID EventRowID         `json:"preview_event_rowid"`
	SortingTimestamp  jsontime.UnixMilli `json:"sorting_timestamp"`
	UnreadCounts
	MarkedUnread *bool `json:"marked_unread,omitempty"`

	PrevBatch string `json:"-"`
}

func (*Room) BumpSortingTimestamp

func (r *Room) BumpSortingTimestamp(evt *Event) bool

func (*Room) CheckChangesAndCopyInto

func (r *Room) CheckChangesAndCopyInto(other *Room) (hasChanges, hasSyncableChanges bool)

func (*Room) EnsureNotNil

func (r *Room) EnsureNotNil()

func (*Room) GetType added in v0.2604.0

func (r *Room) GetType() event.RoomType

func (*Room) Scan

func (r *Room) Scan(row dbutil.Scannable) (*Room, error)

func (*Room) VisibleMetaIsEqual

func (r *Room) VisibleMetaIsEqual(other *Room) bool

type RoomQuery

type RoomQuery struct {
	*dbutil.QueryHelper[*Room]
}

func (*RoomQuery) BumpModTimestamp added in v0.2608.0

func (rq *RoomQuery) BumpModTimestamp(ctx context.Context, roomIDs ...id.RoomID) error

func (*RoomQuery) CalculateUnreads

func (rq *RoomQuery) CalculateUnreads(ctx context.Context, roomID id.RoomID, userID id.UserID) (uc UnreadCounts, err error)

func (*RoomQuery) CreateRow

func (rq *RoomQuery) CreateRow(ctx context.Context, roomID id.RoomID) error

func (*RoomQuery) Delete

func (rq *RoomQuery) Delete(ctx context.Context, roomID id.RoomID) error

func (*RoomQuery) Get

func (rq *RoomQuery) Get(ctx context.Context, roomID id.RoomID) (*Room, error)

func (*RoomQuery) GetAllChangedSince added in v0.2608.0

func (rq *RoomQuery) GetAllChangedSince(ctx context.Context, since int64) ([]*Room, error)

func (*RoomQuery) GetAllSpaces

func (rq *RoomQuery) GetAllSpaces(ctx context.Context) ([]*Room, error)

func (*RoomQuery) GetBySortTS

func (rq *RoomQuery) GetBySortTS(ctx context.Context, maxTS time.Time, limit int) ([]*Room, error)

func (*RoomQuery) GetLeftRoomsSince added in v0.2608.0

func (rq *RoomQuery) GetLeftRoomsSince(ctx context.Context, since int64) ([]id.RoomID, error)

func (*RoomQuery) RecalculatePreview

func (rq *RoomQuery) RecalculatePreview(ctx context.Context, roomID id.RoomID) (rowID EventRowID, err error)

func (*RoomQuery) SetPrevBatch

func (rq *RoomQuery) SetPrevBatch(ctx context.Context, roomID id.RoomID, prevBatch string) error

func (*RoomQuery) Update added in v0.2608.0

func (rq *RoomQuery) Update(ctx context.Context, room *Room) error

func (*RoomQuery) UpdatePreviewIfLaterOnTimeline

func (rq *RoomQuery) UpdatePreviewIfLaterOnTimeline(ctx context.Context, roomID id.RoomID, rowID EventRowID) (previewChanged bool, err error)

type RoomStateGUID

type RoomStateGUID struct {
	RoomID   id.RoomID  `json:"room_id"`
	Type     event.Type `json:"type"`
	StateKey string     `json:"state_key"`
}

type SessionRequest

type SessionRequest struct {
	RoomID        id.RoomID
	SessionID     id.SessionID
	Sender        id.UserID
	MinIndex      uint32
	BackupChecked bool
	RequestSent   bool
}

func (*SessionRequest) Scan

type SessionRequestQuery

type SessionRequestQuery struct {
	*dbutil.QueryHelper[*SessionRequest]
}

func (*SessionRequestQuery) Next

func (srq *SessionRequestQuery) Next(ctx context.Context, count int) ([]*SessionRequest, error)

func (*SessionRequestQuery) Overwrite added in v0.2603.0

func (srq *SessionRequestQuery) Overwrite(ctx context.Context, sr *SessionRequest) error

func (*SessionRequestQuery) Put

func (*SessionRequestQuery) Remove

func (srq *SessionRequestQuery) Remove(ctx context.Context, sessionID id.SessionID, minIndex uint32) error

type SpaceChildEntry

type SpaceChildEntry struct {
	ChildID    id.RoomID
	EventRowID EventRowID
	Order      string
	Suggested  bool
}

func (SpaceChildEntry) GetMassInsertValues

func (sce SpaceChildEntry) GetMassInsertValues() [4]any

type SpaceEdge

type SpaceEdge struct {
	// The room ID of the space (the parent).
	SpaceID id.RoomID `json:"space_id,omitempty"`
	// The room ID of the child room.
	ChildID id.RoomID `json:"child_id"`

	// The event row ID of the `m.space.child` event. Always inside the parent room.
	ChildEventRowID EventRowID `json:"child_event_rowid,omitempty"`
	// The order string contained in the child event used for sorting within the space.
	Order string `json:"order,omitempty"`
	// Whether the space suggests this child room.
	Suggested bool `json:"suggested,omitempty"`

	// The event row ID of the `m.space.parent` event. Always inside the child room.
	ParentEventRowID EventRowID `json:"parent_event_rowid,omitempty"`
	// Whether the room considers the space as canonical.
	Canonical bool `json:"canonical,omitempty"`
	// Whether the parent relationship has been validated (i.e. the sender has sufficient power level in the space).
	// This is not exposed to the frontend, instead the ParentEventRowID and Canonical fields are cleared.
	ParentValidated bool `json:"-"`
}

func (*SpaceEdge) Scan

func (se *SpaceEdge) Scan(row dbutil.Scannable) (*SpaceEdge, error)

type SpaceEdgeQuery

type SpaceEdgeQuery struct {
	*dbutil.QueryHelper[*SpaceEdge]
}

func (*SpaceEdgeQuery) GetAll

func (seq *SpaceEdgeQuery) GetAll(ctx context.Context, spaceID id.RoomID) (map[id.RoomID][]*SpaceEdge, error)

func (*SpaceEdgeQuery) GetTopLevelIDs

func (seq *SpaceEdgeQuery) GetTopLevelIDs(ctx context.Context, userID id.UserID) ([]id.RoomID, error)

func (*SpaceEdgeQuery) RevalidateAllChildrenOfParentValidity

func (seq *SpaceEdgeQuery) RevalidateAllChildrenOfParentValidity(ctx context.Context, spaceID id.RoomID) error

func (*SpaceEdgeQuery) RevalidateAllParentsOfRoomValidity

func (seq *SpaceEdgeQuery) RevalidateAllParentsOfRoomValidity(ctx context.Context, childID id.RoomID) error

func (*SpaceEdgeQuery) RevalidateSpecificParentValidity

func (seq *SpaceEdgeQuery) RevalidateSpecificParentValidity(ctx context.Context, spaceID, childID id.RoomID) error

func (*SpaceEdgeQuery) SetChildren

func (seq *SpaceEdgeQuery) SetChildren(ctx context.Context, spaceID id.RoomID, children []SpaceChildEntry, removedChildren []id.RoomID, clear bool) error

func (*SpaceEdgeQuery) SetParents

func (seq *SpaceEdgeQuery) SetParents(ctx context.Context, childID id.RoomID, parents []SpaceParentEntry, removedParents []id.RoomID, clear bool) error

type SpaceParentEntry

type SpaceParentEntry struct {
	ParentID   id.RoomID
	EventRowID EventRowID
	Canonical  bool
}

func (SpaceParentEntry) GetMassInsertValues

func (spe SpaceParentEntry) GetMassInsertValues() [3]any

type TimelineQuery

type TimelineQuery struct {
	*dbutil.QueryHelper[*Event]
	// contains filtered or unexported fields
}

func (*TimelineQuery) Append

func (tq *TimelineQuery) Append(ctx context.Context, roomID id.RoomID, rowIDs []EventRowID) ([]TimelineRowTuple, error)

Append adds the given event row IDs to the end of the timeline.

func (*TimelineQuery) Clear

func (tq *TimelineQuery) Clear(ctx context.Context, roomID id.RoomID) error

Clear clears the timeline of a given room.

func (*TimelineQuery) Get

func (tq *TimelineQuery) Get(ctx context.Context, roomID id.RoomID, limit int, before TimelineRowID) ([]*Event, error)

func (*TimelineQuery) Has

func (tq *TimelineQuery) Has(ctx context.Context, roomID id.RoomID, eventRowID EventRowID) (exists bool, err error)

func (*TimelineQuery) Prepend

func (tq *TimelineQuery) Prepend(ctx context.Context, roomID id.RoomID, rowIDs []EventRowID) (prependEntries []TimelineRowTuple, err error)

Prepend adds the given event row IDs to the beginning of the timeline. The events must be sorted in reverse chronological order (newest event first).

type TimelineRowID

type TimelineRowID int64

A TimelineRowID is a sorting identifier for events in a room. All events shown in the timeline must have a timeline row ID and must be strictly sorted by that ID.

When new timeline events are received, they get a higher row ID than previous ones. When prepending older events, they receive negative IDs lower than any existing ones.

If the timeline cache for a room is cleared for any reason (either manually or due to a limited sync), the identifiers will be reset for that room and start from higher values than before.

Zero is not a valid value, as it's used to indicate an absent value in some contexts.

type TimelineRowTuple

type TimelineRowTuple struct {
	Timeline TimelineRowID `json:"timeline_rowid"`
	Event    EventRowID    `json:"event_rowid"`
}

A TimelineRowTuple combines a timeline row ID with an event row ID. It is used in the `timeline` field of sync payloads.

func (TimelineRowTuple) GetMassInsertValues

func (trt TimelineRowTuple) GetMassInsertValues() [2]any

type UnreadCounts

type UnreadCounts struct {
	UnreadHighlights    int `json:"unread_highlights"`
	UnreadNotifications int `json:"unread_notifications"`
	UnreadMessages      int `json:"unread_messages"`
}

func (*UnreadCounts) Add

func (uc *UnreadCounts) Add(other UnreadCounts)

func (*UnreadCounts) AddOne

func (uc *UnreadCounts) AddOne(ut UnreadType)

func (*UnreadCounts) IsZero

func (uc *UnreadCounts) IsZero() bool

type UnreadType

type UnreadType int
const (
	UnreadTypeNone      UnreadType = 0b0000
	UnreadTypeNormal    UnreadType = 0b0001
	UnreadTypeNotify    UnreadType = 0b0010
	UnreadTypeHighlight UnreadType = 0b0100
	UnreadTypeSound     UnreadType = 0b1000
)

func (UnreadType) Is

func (ut UnreadType) Is(flag UnreadType) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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