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: 18 Imported by: 12

Documentation

Index

Constants

View Source
const FakeMXIDPrefix = "~fake:"
View Source
const UnfinishedBackfillBackoff = 1 * time.Hour

Variables

View Source
var BackfillNextDispatchNever = time.Unix(0, (1<<63)-1)

Functions

func GetNumberFromMap

func GetNumberFromMap[T constraints.Integer | constraints.Float](m map[string]any, key string) (T, bool)

Types

type BackfillTask added in v0.20.0

type BackfillTask struct {
	BridgeID    networkid.BridgeID
	PortalKey   networkid.PortalKey
	UserLoginID networkid.UserLoginID

	BatchCount        int
	IsDone            bool
	Cursor            networkid.PaginationCursor
	OldestMessageID   networkid.MessageID
	DispatchedAt      time.Time
	CompletedAt       time.Time
	NextDispatchMinTS time.Time
}

func (*BackfillTask) Scan added in v0.20.0

func (bt *BackfillTask) Scan(row dbutil.Scannable) (*BackfillTask, error)

type BackfillTaskQuery added in v0.20.0

type BackfillTaskQuery struct {
	BridgeID networkid.BridgeID
	*dbutil.QueryHelper[*BackfillTask]
}

func (*BackfillTaskQuery) Delete added in v0.20.0

func (btq *BackfillTaskQuery) Delete(ctx context.Context, portalKey networkid.PortalKey) error

func (*BackfillTaskQuery) EnsureExists added in v0.20.0

func (btq *BackfillTaskQuery) EnsureExists(ctx context.Context, portal networkid.PortalKey, loginID networkid.UserLoginID) error

func (*BackfillTaskQuery) GetNext added in v0.20.0

func (btq *BackfillTaskQuery) GetNext(ctx context.Context) (*BackfillTask, error)

func (*BackfillTaskQuery) MarkDispatched added in v0.20.0

func (btq *BackfillTaskQuery) MarkDispatched(ctx context.Context, bq *BackfillTask) error

func (*BackfillTaskQuery) Update added in v0.20.0

func (btq *BackfillTaskQuery) Update(ctx context.Context, bq *BackfillTask) error

func (*BackfillTaskQuery) Upsert added in v0.20.0

func (btq *BackfillTaskQuery) Upsert(ctx context.Context, bq *BackfillTask) error

type Database

type Database struct {
	*dbutil.Database

	BridgeID            networkid.BridgeID
	Portal              *PortalQuery
	Ghost               *GhostQuery
	Message             *MessageQuery
	DisappearingMessage *DisappearingMessageQuery
	Reaction            *ReactionQuery
	User                *UserQuery
	UserLogin           *UserLoginQuery
	UserPortal          *UserPortalQuery
	BackfillTask        *BackfillTaskQuery
	KV                  *KVQuery
}

func New

func New(bridgeID networkid.BridgeID, mt MetaTypes, db *dbutil.Database) *Database

type DisappearingMessage

type DisappearingMessage struct {
	BridgeID networkid.BridgeID
	RoomID   id.RoomID
	EventID  id.EventID
	DisappearingSetting
}

func (*DisappearingMessage) Scan

type DisappearingMessageQuery

type DisappearingMessageQuery struct {
	BridgeID networkid.BridgeID
	*dbutil.QueryHelper[*DisappearingMessage]
}

func (*DisappearingMessageQuery) Delete

func (dmq *DisappearingMessageQuery) Delete(ctx context.Context, eventID id.EventID) error

func (*DisappearingMessageQuery) GetUpcoming

func (dmq *DisappearingMessageQuery) GetUpcoming(ctx context.Context, duration time.Duration) ([]*DisappearingMessage, error)

func (*DisappearingMessageQuery) Put

func (*DisappearingMessageQuery) StartAll

func (dmq *DisappearingMessageQuery) StartAll(ctx context.Context, roomID id.RoomID) ([]*DisappearingMessage, error)

type DisappearingSetting

type DisappearingSetting struct {
	Type        DisappearingType
	Timer       time.Duration
	DisappearAt time.Time
}

DisappearingSetting represents a disappearing message timer setting by combining a type with a timer and an optional start timestamp.

type DisappearingType

type DisappearingType string

DisappearingType represents the type of a disappearing message timer.

const (
	DisappearingTypeNone      DisappearingType = ""
	DisappearingTypeAfterRead DisappearingType = "after_read"
	DisappearingTypeAfterSend DisappearingType = "after_send"
)

type Ghost

type Ghost struct {
	BridgeID networkid.BridgeID
	ID       networkid.UserID

	Name           string
	AvatarID       networkid.AvatarID
	AvatarHash     [32]byte
	AvatarMXC      id.ContentURIString
	NameSet        bool
	AvatarSet      bool
	ContactInfoSet bool
	IsBot          bool
	Identifiers    []string
	Metadata       any
}

func (*Ghost) Scan

func (g *Ghost) Scan(row dbutil.Scannable) (*Ghost, error)

type GhostQuery

type GhostQuery struct {
	BridgeID networkid.BridgeID
	MetaType MetaTypeCreator
	*dbutil.QueryHelper[*Ghost]
}

func (*GhostQuery) GetByID

func (gq *GhostQuery) GetByID(ctx context.Context, id networkid.UserID) (*Ghost, error)

func (*GhostQuery) GetByMetadata added in v0.20.0

func (gq *GhostQuery) GetByMetadata(ctx context.Context, key string, value any) ([]*Ghost, error)

GetByMetadata returns the ghosts whose metadata field at the given JSON key matches the given value.

func (*GhostQuery) Insert

func (gq *GhostQuery) Insert(ctx context.Context, ghost *Ghost) error

func (*GhostQuery) Update

func (gq *GhostQuery) Update(ctx context.Context, ghost *Ghost) error

type KVQuery added in v0.21.0

type KVQuery struct {
	BridgeID networkid.BridgeID
	*dbutil.Database
}

func (*KVQuery) Get added in v0.21.0

func (kvq *KVQuery) Get(ctx context.Context, key Key) string

func (*KVQuery) Set added in v0.21.0

func (kvq *KVQuery) Set(ctx context.Context, key Key, value string)

type Key added in v0.21.0

type Key string
const (
	KeySplitPortalsEnabled Key = "split_portals_enabled"
)

type Message

type Message struct {
	RowID    int64
	BridgeID networkid.BridgeID
	ID       networkid.MessageID
	PartID   networkid.PartID
	MXID     id.EventID

	Room       networkid.PortalKey
	SenderID   networkid.UserID
	SenderMXID id.UserID
	Timestamp  time.Time
	EditCount  int

	ThreadRoot networkid.MessageID
	ReplyTo    networkid.MessageOptionalPartID

	Metadata any
}

func (*Message) HasFakeMXID added in v0.20.0

func (m *Message) HasFakeMXID() bool

func (*Message) Scan

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

func (*Message) SetFakeMXID added in v0.20.0

func (m *Message) SetFakeMXID()

type MessageQuery

type MessageQuery struct {
	BridgeID networkid.BridgeID
	MetaType MetaTypeCreator
	*dbutil.QueryHelper[*Message]
}

func (*MessageQuery) CountMessagesInPortal added in v0.20.0

func (mq *MessageQuery) CountMessagesInPortal(ctx context.Context, key networkid.PortalKey) (count int, err error)

func (*MessageQuery) Delete

func (mq *MessageQuery) Delete(ctx context.Context, rowID int64) error

func (*MessageQuery) DeleteAllParts

func (mq *MessageQuery) DeleteAllParts(ctx context.Context, receiver networkid.UserLoginID, id networkid.MessageID) error

func (*MessageQuery) GetAllPartsByID

func (mq *MessageQuery) GetAllPartsByID(ctx context.Context, receiver networkid.UserLoginID, id networkid.MessageID) ([]*Message, error)

func (*MessageQuery) GetByRowID

func (mq *MessageQuery) GetByRowID(ctx context.Context, rowID int64) (*Message, error)

func (*MessageQuery) GetFirstOrSpecificPartByID

func (mq *MessageQuery) GetFirstOrSpecificPartByID(ctx context.Context, receiver networkid.UserLoginID, id networkid.MessageOptionalPartID) (*Message, error)

func (*MessageQuery) GetFirstPartByID

func (mq *MessageQuery) GetFirstPartByID(ctx context.Context, receiver networkid.UserLoginID, id networkid.MessageID) (*Message, error)

func (*MessageQuery) GetFirstPortalMessage added in v0.20.0

func (mq *MessageQuery) GetFirstPortalMessage(ctx context.Context, portal networkid.PortalKey) (*Message, error)

func (*MessageQuery) GetFirstThreadMessage

func (mq *MessageQuery) GetFirstThreadMessage(ctx context.Context, portal networkid.PortalKey, threadRoot networkid.MessageID) (*Message, error)

func (*MessageQuery) GetLastPartAtOrBeforeTime

func (mq *MessageQuery) GetLastPartAtOrBeforeTime(ctx context.Context, portal networkid.PortalKey, maxTS time.Time) (*Message, error)

func (*MessageQuery) GetLastPartByID

func (mq *MessageQuery) GetLastPartByID(ctx context.Context, receiver networkid.UserLoginID, id networkid.MessageID) (*Message, error)

func (*MessageQuery) GetLastThreadMessage

func (mq *MessageQuery) GetLastThreadMessage(ctx context.Context, portal networkid.PortalKey, threadRoot networkid.MessageID) (*Message, error)

func (*MessageQuery) GetMessagesBetweenTimeQuery

func (mq *MessageQuery) GetMessagesBetweenTimeQuery(ctx context.Context, portal networkid.PortalKey, start, end time.Time) ([]*Message, error)

func (*MessageQuery) GetPartByID

func (mq *MessageQuery) GetPartByID(ctx context.Context, receiver networkid.UserLoginID, id networkid.MessageID, partID networkid.PartID) (*Message, error)

func (*MessageQuery) GetPartByMXID

func (mq *MessageQuery) GetPartByMXID(ctx context.Context, mxid id.EventID) (*Message, error)

func (*MessageQuery) Insert

func (mq *MessageQuery) Insert(ctx context.Context, msg *Message) error

func (*MessageQuery) Update

func (mq *MessageQuery) Update(ctx context.Context, msg *Message) error

type MetaMerger

type MetaMerger interface {
	CopyFrom(other any)
}

type MetaTypeCreator

type MetaTypeCreator func() any

type MetaTypes

type MetaTypes struct {
	Portal    MetaTypeCreator
	Ghost     MetaTypeCreator
	Message   MetaTypeCreator
	Reaction  MetaTypeCreator
	UserLogin MetaTypeCreator
}

type Portal

type Portal struct {
	BridgeID networkid.BridgeID
	networkid.PortalKey
	MXID id.RoomID

	ParentKey    networkid.PortalKey
	RelayLoginID networkid.UserLoginID
	OtherUserID  networkid.UserID
	Name         string
	Topic        string
	AvatarID     networkid.AvatarID
	AvatarHash   [32]byte
	AvatarMXC    id.ContentURIString
	NameSet      bool
	TopicSet     bool
	AvatarSet    bool
	NameIsCustom bool
	InSpace      bool
	RoomType     RoomType
	Disappear    DisappearingSetting
	Metadata     any
}

func (*Portal) Scan

func (p *Portal) Scan(row dbutil.Scannable) (*Portal, error)

type PortalQuery

type PortalQuery struct {
	BridgeID networkid.BridgeID
	MetaType MetaTypeCreator
	*dbutil.QueryHelper[*Portal]
}

func (*PortalQuery) Delete

func (pq *PortalQuery) Delete(ctx context.Context, key networkid.PortalKey) error

func (*PortalQuery) FindReceiver

func (pq *PortalQuery) FindReceiver(ctx context.Context, id networkid.PortalID, maybeReceiver networkid.UserLoginID) (key networkid.PortalKey, err error)

func (*PortalQuery) GetAll added in v0.20.0

func (pq *PortalQuery) GetAll(ctx context.Context) ([]*Portal, error)

func (*PortalQuery) GetAllDMsWith added in v0.20.0

func (pq *PortalQuery) GetAllDMsWith(ctx context.Context, otherUserID networkid.UserID) ([]*Portal, error)

func (*PortalQuery) GetAllWithMXID

func (pq *PortalQuery) GetAllWithMXID(ctx context.Context) ([]*Portal, error)

func (*PortalQuery) GetByIDWithUncertainReceiver

func (pq *PortalQuery) GetByIDWithUncertainReceiver(ctx context.Context, key networkid.PortalKey) (*Portal, error)

func (*PortalQuery) GetByKey

func (pq *PortalQuery) GetByKey(ctx context.Context, key networkid.PortalKey) (*Portal, error)

func (*PortalQuery) GetByMXID

func (pq *PortalQuery) GetByMXID(ctx context.Context, mxid id.RoomID) (*Portal, error)

func (*PortalQuery) GetChildren

func (pq *PortalQuery) GetChildren(ctx context.Context, parentKey networkid.PortalKey) ([]*Portal, error)

func (*PortalQuery) Insert

func (pq *PortalQuery) Insert(ctx context.Context, p *Portal) error

func (*PortalQuery) MigrateToSplitPortals added in v0.21.0

func (pq *PortalQuery) MigrateToSplitPortals(ctx context.Context) (int64, error)

func (*PortalQuery) ReID

func (pq *PortalQuery) ReID(ctx context.Context, oldID, newID networkid.PortalKey) error

func (*PortalQuery) Update

func (pq *PortalQuery) Update(ctx context.Context, p *Portal) error

type Reaction

type Reaction struct {
	BridgeID      networkid.BridgeID
	Room          networkid.PortalKey
	MessageID     networkid.MessageID
	MessagePartID networkid.PartID
	SenderID      networkid.UserID
	SenderMXID    id.UserID
	EmojiID       networkid.EmojiID
	MXID          id.EventID

	Timestamp time.Time
	Emoji     string
	Metadata  any
}

func (*Reaction) Scan

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

type ReactionQuery

type ReactionQuery struct {
	BridgeID networkid.BridgeID
	MetaType MetaTypeCreator
	*dbutil.QueryHelper[*Reaction]
}

func (*ReactionQuery) Delete

func (rq *ReactionQuery) Delete(ctx context.Context, reaction *Reaction) error

func (*ReactionQuery) GetAllToMessage

func (rq *ReactionQuery) GetAllToMessage(ctx context.Context, messageID networkid.MessageID) ([]*Reaction, error)

func (*ReactionQuery) GetAllToMessageBySender

func (rq *ReactionQuery) GetAllToMessageBySender(ctx context.Context, messageID networkid.MessageID, senderID networkid.UserID) ([]*Reaction, error)

func (*ReactionQuery) GetAllToMessagePart added in v0.20.0

func (rq *ReactionQuery) GetAllToMessagePart(ctx context.Context, messageID networkid.MessageID, partID networkid.PartID) ([]*Reaction, error)

func (*ReactionQuery) GetByID

func (rq *ReactionQuery) GetByID(ctx context.Context, messageID networkid.MessageID, messagePartID networkid.PartID, senderID networkid.UserID, emojiID networkid.EmojiID) (*Reaction, error)

func (*ReactionQuery) GetByIDWithoutMessagePart

func (rq *ReactionQuery) GetByIDWithoutMessagePart(ctx context.Context, messageID networkid.MessageID, senderID networkid.UserID, emojiID networkid.EmojiID) (*Reaction, error)

func (*ReactionQuery) GetByMXID

func (rq *ReactionQuery) GetByMXID(ctx context.Context, mxid id.EventID) (*Reaction, error)

func (*ReactionQuery) Upsert

func (rq *ReactionQuery) Upsert(ctx context.Context, reaction *Reaction) error

type RoomType

type RoomType string
const (
	RoomTypeDefault RoomType = ""
	RoomTypeDM      RoomType = "dm"
	RoomTypeGroupDM RoomType = "group_dm"
	RoomTypeSpace   RoomType = "space"
)

type User

type User struct {
	BridgeID networkid.BridgeID
	MXID     id.UserID

	ManagementRoom id.RoomID
	AccessToken    string
}

func (*User) Scan

func (u *User) Scan(row dbutil.Scannable) (*User, error)

type UserLogin

type UserLogin struct {
	BridgeID      networkid.BridgeID
	UserMXID      id.UserID
	ID            networkid.UserLoginID
	RemoteName    string
	RemoteProfile status.RemoteProfile
	SpaceRoom     id.RoomID
	Metadata      any
}

func (*UserLogin) Scan

func (u *UserLogin) Scan(row dbutil.Scannable) (*UserLogin, error)

type UserLoginQuery

type UserLoginQuery struct {
	BridgeID networkid.BridgeID
	MetaType MetaTypeCreator
	*dbutil.QueryHelper[*UserLogin]
}

func (*UserLoginQuery) Delete

func (uq *UserLoginQuery) Delete(ctx context.Context, loginID networkid.UserLoginID) error

func (*UserLoginQuery) GetAllForUser

func (uq *UserLoginQuery) GetAllForUser(ctx context.Context, userID id.UserID) ([]*UserLogin, error)

func (*UserLoginQuery) GetAllInPortal

func (uq *UserLoginQuery) GetAllInPortal(ctx context.Context, portal networkid.PortalKey) ([]*UserLogin, error)

func (*UserLoginQuery) GetAllUserIDsWithLogins

func (uq *UserLoginQuery) GetAllUserIDsWithLogins(ctx context.Context) ([]id.UserID, error)

func (*UserLoginQuery) GetByID

func (*UserLoginQuery) Insert

func (uq *UserLoginQuery) Insert(ctx context.Context, login *UserLogin) error

func (*UserLoginQuery) Update

func (uq *UserLoginQuery) Update(ctx context.Context, login *UserLogin) error

type UserPortal

type UserPortal struct {
	BridgeID  networkid.BridgeID
	UserMXID  id.UserID
	LoginID   networkid.UserLoginID
	Portal    networkid.PortalKey
	InSpace   *bool
	Preferred *bool
	LastRead  time.Time
}

func UserPortalFor

func UserPortalFor(ul *UserLogin, portal networkid.PortalKey) *UserPortal

func (*UserPortal) CopyWithoutValues

func (up *UserPortal) CopyWithoutValues() *UserPortal

func (*UserPortal) Scan

func (up *UserPortal) Scan(row dbutil.Scannable) (*UserPortal, error)

type UserPortalQuery

type UserPortalQuery struct {
	BridgeID networkid.BridgeID
	*dbutil.QueryHelper[*UserPortal]
}

func (*UserPortalQuery) Delete added in v0.20.0

func (upq *UserPortalQuery) Delete(ctx context.Context, up *UserPortal) error

func (*UserPortalQuery) Get

func (upq *UserPortalQuery) Get(ctx context.Context, login *UserLogin, portal networkid.PortalKey) (*UserPortal, error)

func (*UserPortalQuery) GetAllForLogin

func (upq *UserPortalQuery) GetAllForLogin(ctx context.Context, login *UserLogin) ([]*UserPortal, error)

func (*UserPortalQuery) GetAllForUserInPortal

func (upq *UserPortalQuery) GetAllForUserInPortal(ctx context.Context, userID id.UserID, portal networkid.PortalKey) ([]*UserPortal, error)

func (*UserPortalQuery) GetAllInPortal

func (upq *UserPortalQuery) GetAllInPortal(ctx context.Context, portal networkid.PortalKey) ([]*UserPortal, error)

func (*UserPortalQuery) GetOrCreate

func (upq *UserPortalQuery) GetOrCreate(ctx context.Context, login *UserLogin, portal networkid.PortalKey) (*UserPortal, error)

func (*UserPortalQuery) MarkAsPreferred

func (upq *UserPortalQuery) MarkAsPreferred(ctx context.Context, login *UserLogin, portal networkid.PortalKey) error

func (*UserPortalQuery) Put

func (upq *UserPortalQuery) Put(ctx context.Context, up *UserPortal) error

type UserQuery

type UserQuery struct {
	BridgeID networkid.BridgeID
	*dbutil.QueryHelper[*User]
}

func (*UserQuery) GetByMXID

func (uq *UserQuery) GetByMXID(ctx context.Context, userID id.UserID) (*User, error)

func (*UserQuery) Insert

func (uq *UserQuery) Insert(ctx context.Context, user *User) error

func (*UserQuery) Update

func (uq *UserQuery) Update(ctx context.Context, user *User) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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