database

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

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
	DeviceID      id.DeviceID
	AccessToken   string
	HomeserverURL string
	NextBatch     string
}

func (*Account) Scan

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

type AccountData

type AccountData struct {
	UserID  id.UserID
	RoomID  id.RoomID
	Type    string
	Content json.RawMessage
}

func (*AccountData) Scan

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

type AccountDataQuery

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

func (*AccountDataQuery) Put

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

func (*AccountDataQuery) PutRoom

func (adq *AccountDataQuery) PutRoom(ctx context.Context, userID id.UserID, roomID id.RoomID, eventType event.Type, content json.RawMessage) 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

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 added in v0.21.0

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

func (*ClientStateStore) GetEncryptionEvent

func (c *ClientStateStore) GetEncryptionEvent(ctx context.Context, roomID id.RoomID) (content *event.EncryptionEventContent, 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 added in v0.21.0

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

func (*ClientStateStore) IsConfusableName added in v0.20.0

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 added in v0.21.0

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

func (*ClientStateStore) ReplaceCachedMembers added in v0.21.0

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

func (*ClientStateStore) SetEncryptionEvent

func (c *ClientStateStore) SetEncryptionEvent(ctx context.Context, roomID id.RoomID, content *event.EncryptionEventContent) 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 CurrentStateQuery

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

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) 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
	Event          EventQuery
	CurrentState   CurrentStateQuery
	Timeline       TimelineQuery
	SessionRequest SessionRequestQuery
	Receipt        ReceiptQuery
}

func New

func New(rawDB *dbutil.Database) *Database

type Event

type Event struct {
	RowID         EventRowID    `json:"rowid"`
	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 time.Time  `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"`

	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:"-,omitempty"`
	DecryptionError string       `json:"decryption_error,omitempty"`

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

func MautrixToEvent

func MautrixToEvent(evt *event.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) 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) GetByID

func (eq *EventQuery) GetByID(ctx context.Context, 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) 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) GetReactions

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

func (*EventQuery) Insert

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

func (*EventQuery) UpdateDecrypted

func (eq *EventQuery) UpdateDecrypted(ctx context.Context, rowID EventRowID, decrypted json.RawMessage, decryptedType string) error

func (*EventQuery) UpdateID

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

func (*EventQuery) Upsert

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

type EventRowID

type EventRowID int64

func (EventRowID) GetMassInsertValues

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

type GetReactionsResult

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

type NameQuality

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

type Receipt

type Receipt struct {
	RoomID      id.RoomID
	UserID      id.UserID
	ReceiptType event.ReceiptType
	ThreadID    event.ThreadID
	EventID     id.EventID
	Timestamp   time.Time
}

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) 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"`

	Name           *string        `json:"name,omitempty"`
	NameQuality    NameQuality    `json:"name_quality"`
	Avatar         *id.ContentURI `json:"avatar,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  time.Time  `json:"sorting_timestamp"`

	PrevBatch string `json:"prev_batch"`
}

func (*Room) BumpSortingTimestamp

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

func (*Room) CheckChangesAndCopyInto

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

func (*Room) Scan

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

type RoomQuery

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

func (*RoomQuery) CreateRow

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

func (*RoomQuery) Get

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

func (*RoomQuery) SetPrevBatch

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

func (*RoomQuery) UpdatePreviewIfLaterOnTimeline

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

func (*RoomQuery) Upsert

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

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) Put

func (*SessionRequestQuery) Remove

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

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) 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

type TimelineRowTuple

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

func (TimelineRowTuple) GetMassInsertValues

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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