database

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackfillState added in v0.5.0

type BackfillState struct {
	UserID                 id.UserID
	Portal                 PortalKey
	ProcessingBatch        bool
	BackfillComplete       bool
	FirstExpectedTimestamp uint64
	// contains filtered or unexported fields
}

func (*BackfillState) Scan added in v0.5.0

func (*BackfillState) SetProcessingBatch added in v0.5.0

func (b *BackfillState) SetProcessingBatch(ctx context.Context, processing bool) error

func (*BackfillState) Upsert added in v0.5.0

func (b *BackfillState) Upsert(ctx context.Context) error

type BackfillStateQuery added in v0.10.6

type BackfillStateQuery struct {
	*dbutil.QueryHelper[*BackfillState]
}

func (*BackfillStateQuery) GetBackfillState added in v0.10.6

func (bq *BackfillStateQuery) GetBackfillState(ctx context.Context, userID id.UserID, portalKey PortalKey) (*BackfillState, error)

func (*BackfillStateQuery) NewBackfillState added in v0.10.6

func (bq *BackfillStateQuery) NewBackfillState(userID id.UserID, portalKey PortalKey) *BackfillState

type BackfillTask added in v0.10.6

type BackfillTask struct {
	QueueID        int
	UserID         id.UserID
	BackfillType   BackfillType
	Priority       int
	Portal         PortalKey
	TimeStart      *time.Time
	MaxBatchEvents int
	MaxTotalEvents int
	BatchDelay     int
	DispatchTime   *time.Time
	CompletedAt    *time.Time
	// contains filtered or unexported fields
}

func (*BackfillTask) Insert added in v0.10.6

func (b *BackfillTask) Insert(ctx context.Context) error

func (*BackfillTask) MarkDispatched added in v0.10.6

func (b *BackfillTask) MarkDispatched(ctx context.Context) error

func (*BackfillTask) MarkDone added in v0.10.6

func (b *BackfillTask) MarkDone(ctx context.Context) error

func (*BackfillTask) MarshalZerologObject added in v0.10.6

func (b *BackfillTask) MarshalZerologObject(evt *zerolog.Event)

func (*BackfillTask) Scan added in v0.10.6

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

func (*BackfillTask) String added in v0.10.6

func (b *BackfillTask) String() string

type BackfillTaskQuery added in v0.10.6

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

func (*BackfillTaskQuery) DeleteAll added in v0.10.6

func (bq *BackfillTaskQuery) DeleteAll(ctx context.Context, userID id.UserID) error

func (*BackfillTaskQuery) DeleteAllForPortal added in v0.10.6

func (bq *BackfillTaskQuery) DeleteAllForPortal(ctx context.Context, userID id.UserID, portalKey PortalKey) error

func (*BackfillTaskQuery) GetNext added in v0.10.6

func (bq *BackfillTaskQuery) GetNext(ctx context.Context, userID id.UserID, backfillTypes []BackfillType) (*BackfillTask, error)

GetNext returns the next backfill to perform

func (*BackfillTaskQuery) HasUnstartedOrInFlightOfType added in v0.10.6

func (bq *BackfillTaskQuery) HasUnstartedOrInFlightOfType(ctx context.Context, userID id.UserID, backfillTypes []BackfillType) (has bool)

func (*BackfillTaskQuery) NewWithValues added in v0.10.6

func (bq *BackfillTaskQuery) NewWithValues(userID id.UserID, backfillType BackfillType, priority int, portal PortalKey, timeStart *time.Time, maxBatchEvents, maxTotalEvents, batchDelay int) *BackfillTask

type BackfillType added in v0.4.0

type BackfillType int
const (
	BackfillImmediate BackfillType = 0
	BackfillForward   BackfillType = 100
	BackfillDeferred  BackfillType = 200
)

func (BackfillType) String added in v0.4.0

func (bt BackfillType) String() string

type Database

type Database struct {
	*dbutil.Database

	User     *UserQuery
	Portal   *PortalQuery
	Puppet   *PuppetQuery
	Message  *MessageQuery
	Reaction *ReactionQuery

	DisappearingMessage  *DisappearingMessageQuery
	BackfillQueue        *BackfillTaskQuery
	BackfillState        *BackfillStateQuery
	HistorySync          *HistorySyncQuery
	MediaBackfillRequest *MediaBackfillRequestQuery
}

func New

func New(db *dbutil.Database) *Database

func (*Database) HandleSignalStoreError added in v0.4.0

func (db *Database) HandleSignalStoreError(device *store.Device, action string, attemptIndex int, err error) (retry bool)

type DisappearingMessage added in v0.2.3

type DisappearingMessage struct {
	RoomID   id.RoomID
	EventID  id.EventID
	ExpireIn time.Duration
	ExpireAt time.Time
	// contains filtered or unexported fields
}

func (*DisappearingMessage) Delete added in v0.2.3

func (msg *DisappearingMessage) Delete(ctx context.Context) error

func (*DisappearingMessage) Insert added in v0.2.3

func (msg *DisappearingMessage) Insert(ctx context.Context) error

func (*DisappearingMessage) Scan added in v0.2.3

func (*DisappearingMessage) StartTimer added in v0.2.3

func (msg *DisappearingMessage) StartTimer(ctx context.Context) error

type DisappearingMessageQuery added in v0.2.3

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

func (*DisappearingMessageQuery) GetUpcomingScheduled added in v0.2.3

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

func (*DisappearingMessageQuery) NewWithValues added in v0.2.3

func (dmq *DisappearingMessageQuery) NewWithValues(roomID id.RoomID, eventID id.EventID, expireIn time.Duration, expireAt time.Time) *DisappearingMessage

type HistorySyncConversation added in v0.4.0

type HistorySyncConversation struct {
	UserID                   id.UserID
	ConversationID           string
	PortalKey                PortalKey
	LastMessageTimestamp     time.Time
	MuteEndTime              time.Time
	Archived                 bool
	Pinned                   uint32
	DisappearingMode         waProto.DisappearingMode_Initiator
	EndOfHistoryTransferType waProto.Conversation_EndOfHistoryTransferType
	EphemeralExpiration      *uint32
	MarkedAsUnread           bool
	UnreadCount              uint32
	// contains filtered or unexported fields
}

func (*HistorySyncConversation) Scan added in v0.4.0

func (*HistorySyncConversation) Upsert added in v0.4.0

func (hsc *HistorySyncConversation) Upsert(ctx context.Context) error

type HistorySyncMessage added in v0.4.0

type HistorySyncMessage struct {
	UserID         id.UserID
	ConversationID string
	MessageID      string
	Timestamp      time.Time
	Data           []byte
	// contains filtered or unexported fields
}

func (*HistorySyncMessage) Insert added in v0.4.0

func (hsm *HistorySyncMessage) Insert(ctx context.Context) error

type HistorySyncQuery added in v0.4.0

type HistorySyncQuery struct {
	*dbutil.QueryHelper[*HistorySyncConversation]
}

func (*HistorySyncQuery) ConversationHasMessages added in v0.10.3

func (hsq *HistorySyncQuery) ConversationHasMessages(ctx context.Context, userID id.UserID, portalKey PortalKey) (exists bool, err error)

func (*HistorySyncQuery) DeleteAllConversations added in v0.4.0

func (hsq *HistorySyncQuery) DeleteAllConversations(ctx context.Context, userID id.UserID) error

func (*HistorySyncQuery) DeleteAllMessages added in v0.4.0

func (hsq *HistorySyncQuery) DeleteAllMessages(ctx context.Context, userID id.UserID) error

func (*HistorySyncQuery) DeleteAllMessagesForPortal added in v0.4.0

func (hsq *HistorySyncQuery) DeleteAllMessagesForPortal(ctx context.Context, userID id.UserID, portalKey PortalKey) error

func (*HistorySyncQuery) DeleteConversation added in v0.9.0

func (hsq *HistorySyncQuery) DeleteConversation(ctx context.Context, userID id.UserID, jid string) error

func (*HistorySyncQuery) DeleteMessages added in v0.4.0

func (hsq *HistorySyncQuery) DeleteMessages(ctx context.Context, userID id.UserID, conversationID string, messages []*waProto.WebMessageInfo) error

func (*HistorySyncQuery) GetConversation added in v0.4.0

func (hsq *HistorySyncQuery) GetConversation(ctx context.Context, userID id.UserID, portalKey PortalKey) (*HistorySyncConversation, error)

func (*HistorySyncQuery) GetMessagesBetween added in v0.4.0

func (hsq *HistorySyncQuery) GetMessagesBetween(ctx context.Context, userID id.UserID, conversationID string, startTime, endTime *time.Time, limit int) ([]*waProto.WebMessageInfo, error)

func (*HistorySyncQuery) GetRecentConversations added in v0.9.0

func (hsq *HistorySyncQuery) GetRecentConversations(ctx context.Context, userID id.UserID, n int) ([]*HistorySyncConversation, error)

func (*HistorySyncQuery) NewConversationWithValues added in v0.4.0

func (hsq *HistorySyncQuery) NewConversationWithValues(
	userID id.UserID,
	conversationID string,
	portalKey PortalKey,
	lastMessageTimestamp,
	muteEndTime uint64,
	archived bool,
	pinned uint32,
	disappearingMode waProto.DisappearingMode_Initiator,
	endOfHistoryTransferType waProto.Conversation_EndOfHistoryTransferType,
	ephemeralExpiration *uint32,
	markedAsUnread bool,
	unreadCount uint32,
) *HistorySyncConversation

func (*HistorySyncQuery) NewMessageWithValues added in v0.4.0

func (hsq *HistorySyncQuery) NewMessageWithValues(userID id.UserID, conversationID, messageID string, message *waProto.HistorySyncMsg) (*HistorySyncMessage, error)

type MediaBackfillRequest added in v0.4.0

type MediaBackfillRequest struct {
	UserID    id.UserID
	PortalKey PortalKey
	EventID   id.EventID
	MediaKey  []byte
	Status    MediaBackfillRequestStatus
	Error     string
	// contains filtered or unexported fields
}

func (*MediaBackfillRequest) Scan added in v0.4.0

func (*MediaBackfillRequest) Upsert added in v0.4.0

func (mbr *MediaBackfillRequest) Upsert(ctx context.Context) error

type MediaBackfillRequestQuery added in v0.4.0

type MediaBackfillRequestQuery struct {
	*dbutil.QueryHelper[*MediaBackfillRequest]
}

func (*MediaBackfillRequestQuery) DeleteAllMediaBackfillRequests added in v0.4.0

func (mbrq *MediaBackfillRequestQuery) DeleteAllMediaBackfillRequests(ctx context.Context, userID id.UserID) error

func (*MediaBackfillRequestQuery) GetMediaBackfillRequestsForUser added in v0.4.0

func (mbrq *MediaBackfillRequestQuery) GetMediaBackfillRequestsForUser(ctx context.Context, userID id.UserID) ([]*MediaBackfillRequest, error)

func (*MediaBackfillRequestQuery) NewMediaBackfillRequestWithValues added in v0.4.0

func (mbrq *MediaBackfillRequestQuery) NewMediaBackfillRequestWithValues(userID id.UserID, portalKey PortalKey, eventID id.EventID, mediaKey []byte) *MediaBackfillRequest

type MediaBackfillRequestStatus added in v0.4.0

type MediaBackfillRequestStatus int
const (
	MediaBackfillRequestStatusNotRequested MediaBackfillRequestStatus = iota
	MediaBackfillRequestStatusRequested
	MediaBackfillRequestStatusRequestFailed
)

type Message

type Message struct {
	Chat       PortalKey
	JID        types.MessageID
	MXID       id.EventID
	Sender     types.JID
	SenderMXID id.UserID
	Timestamp  time.Time
	Sent       bool
	Type       MessageType
	Error      MessageErrorType

	GalleryPart int

	BroadcastListJID types.JID
	// contains filtered or unexported fields
}

func (*Message) Delete

func (msg *Message) Delete(ctx context.Context) error

func (*Message) GetPollOptionHashes added in v0.8.1

func (msg *Message) GetPollOptionHashes(ctx context.Context, ids []string) (map[string][32]byte, error)

func (*Message) GetPollOptionIDs added in v0.8.1

func (msg *Message) GetPollOptionIDs(ctx context.Context, hashes [][]byte) (map[[32]byte]string, error)

func (*Message) Insert

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

func (*Message) IsFakeJID added in v0.2.1

func (msg *Message) IsFakeJID() bool

func (*Message) IsFakeMXID added in v0.1.6

func (msg *Message) IsFakeMXID() bool

func (*Message) MarkSent added in v0.1.6

func (msg *Message) MarkSent(ctx context.Context, ts time.Time) error

func (*Message) PutPollOptions added in v0.8.1

func (msg *Message) PutPollOptions(ctx context.Context, opts map[[32]byte]string) error

func (*Message) Scan

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

func (*Message) UpdateMXID added in v0.2.1

func (msg *Message) UpdateMXID(ctx context.Context, mxid id.EventID, newType MessageType, newError MessageErrorType) error

type MessageErrorType added in v0.2.4

type MessageErrorType string
const (
	MsgNoError             MessageErrorType = ""
	MsgErrDecryptionFailed MessageErrorType = "decryption_failed"
	MsgErrMediaNotFound    MessageErrorType = "media_not_found"
)

type MessageQuery

type MessageQuery struct {
	*dbutil.QueryHelper[*Message]
}

func (*MessageQuery) GetAll

func (mq *MessageQuery) GetAll(ctx context.Context, chat PortalKey) ([]*Message, error)

func (*MessageQuery) GetByJID

func (mq *MessageQuery) GetByJID(ctx context.Context, chat PortalKey, jid types.MessageID) (*Message, error)

func (*MessageQuery) GetByMXID

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

func (*MessageQuery) GetFirstInChat added in v0.2.1

func (mq *MessageQuery) GetFirstInChat(ctx context.Context, chat PortalKey) (*Message, error)

func (*MessageQuery) GetLastInChat

func (mq *MessageQuery) GetLastInChat(ctx context.Context, chat PortalKey) (*Message, error)

func (*MessageQuery) GetLastInChatBefore added in v0.1.7

func (mq *MessageQuery) GetLastInChatBefore(ctx context.Context, chat PortalKey, maxTimestamp time.Time) (*Message, error)

func (*MessageQuery) GetMessagesBetween added in v0.2.2

func (mq *MessageQuery) GetMessagesBetween(ctx context.Context, chat PortalKey, minTimestamp, maxTimestamp time.Time) ([]*Message, error)

type MessageType added in v0.3.0

type MessageType string
const (
	MsgUnknown       MessageType = ""
	MsgFake          MessageType = "fake"
	MsgNormal        MessageType = "message"
	MsgReaction      MessageType = "reaction"
	MsgEdit          MessageType = "edit"
	MsgMatrixPoll    MessageType = "matrix-poll"
	MsgBeeperGallery MessageType = "beeper-gallery"
)

type Portal

type Portal struct {
	Key  PortalKey
	MXID id.RoomID

	Name      string
	NameSet   bool
	Topic     string
	TopicSet  bool
	Avatar    string
	AvatarURL id.ContentURI
	AvatarSet bool
	Encrypted bool
	LastSync  time.Time

	IsParent    bool
	ParentGroup types.JID
	InSpace     bool

	FirstEventID   id.EventID
	NextBatchID    id.BatchID
	RelayUserID    id.UserID
	ExpirationTime uint32
	// contains filtered or unexported fields
}

func (*Portal) Delete

func (portal *Portal) Delete(ctx context.Context) error

func (*Portal) Insert

func (portal *Portal) Insert(ctx context.Context) error

func (*Portal) Scan

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

func (*Portal) Update

func (portal *Portal) Update(ctx context.Context) error

type PortalKey

type PortalKey struct {
	JID      types.JID
	Receiver types.JID
}

func NewPortalKey

func NewPortalKey(jid, receiver types.JID) PortalKey

func (PortalKey) String

func (key PortalKey) String() string

type PortalQuery

type PortalQuery struct {
	*dbutil.QueryHelper[*Portal]
}

func (*PortalQuery) FindPrivateChats added in v0.1.4

func (pq *PortalQuery) FindPrivateChats(ctx context.Context, receiver types.JID) ([]*Portal, error)

func (*PortalQuery) FindPrivateChatsNotInSpace added in v0.2.3

func (pq *PortalQuery) FindPrivateChatsNotInSpace(ctx context.Context, receiver types.JID) (keys []PortalKey, err error)

func (*PortalQuery) GetAll

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

func (*PortalQuery) GetAllByJID

func (pq *PortalQuery) GetAllByJID(ctx context.Context, jid types.JID) ([]*Portal, error)

func (*PortalQuery) GetAllByParentGroup added in v0.8.0

func (pq *PortalQuery) GetAllByParentGroup(ctx context.Context, jid types.JID) ([]*Portal, error)

func (*PortalQuery) GetByJID

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

func (*PortalQuery) GetByMXID

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

type Puppet

type Puppet struct {
	JID            types.JID
	Avatar         string
	AvatarURL      id.ContentURI
	AvatarSet      bool
	Displayname    string
	NameQuality    int8
	NameSet        bool
	ContactInfoSet bool
	LastSync       time.Time

	CustomMXID     id.UserID
	AccessToken    string
	NextBatch      string
	EnablePresence bool
	EnableReceipts bool
	// contains filtered or unexported fields
}

func (*Puppet) Insert

func (puppet *Puppet) Insert(ctx context.Context) error

func (*Puppet) Scan

func (puppet *Puppet) Scan(row dbutil.Scannable) (*Puppet, error)

func (*Puppet) Update

func (puppet *Puppet) Update(ctx context.Context) error

type PuppetQuery

type PuppetQuery struct {
	*dbutil.QueryHelper[*Puppet]
}

func (*PuppetQuery) Get

func (pq *PuppetQuery) Get(ctx context.Context, jid types.JID) (*Puppet, error)

func (*PuppetQuery) GetAll

func (pq *PuppetQuery) GetAll(ctx context.Context) ([]*Puppet, error)

func (*PuppetQuery) GetAllWithCustomMXID

func (pq *PuppetQuery) GetAllWithCustomMXID(ctx context.Context) ([]*Puppet, error)

func (*PuppetQuery) GetByCustomMXID

func (pq *PuppetQuery) GetByCustomMXID(ctx context.Context, mxid id.UserID) (*Puppet, error)

type Reaction added in v0.3.0

type Reaction struct {
	Chat      PortalKey
	TargetJID types.MessageID
	Sender    types.JID
	MXID      id.EventID
	JID       types.MessageID
	// contains filtered or unexported fields
}

func (*Reaction) Delete added in v0.3.0

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

func (*Reaction) Scan added in v0.3.0

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

func (*Reaction) Upsert added in v0.3.0

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

type ReactionQuery added in v0.3.0

type ReactionQuery struct {
	*dbutil.QueryHelper[*Reaction]
}

func (*ReactionQuery) GetByMXID added in v0.3.0

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

func (*ReactionQuery) GetByTargetJID added in v0.3.0

func (rq *ReactionQuery) GetByTargetJID(ctx context.Context, chat PortalKey, jid types.MessageID, sender types.JID) (*Reaction, error)

type User

type User struct {
	MXID            id.UserID
	JID             types.JID
	ManagementRoom  id.RoomID
	SpaceRoom       id.RoomID
	PhoneLastSeen   time.Time
	PhoneLastPinged time.Time
	Timezone        string
	// contains filtered or unexported fields
}

func (*User) GetLastAppStateKeyID added in v0.4.0

func (user *User) GetLastAppStateKeyID(ctx context.Context) (keyID []byte, err error)

func (*User) GetLastReadTS added in v0.2.2

func (user *User) GetLastReadTS(ctx context.Context, portal PortalKey) time.Time

func (*User) Insert

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

func (*User) IsInSpace added in v0.2.3

func (user *User) IsInSpace(ctx context.Context, portal PortalKey) bool

func (*User) MarkInSpace added in v0.2.3

func (user *User) MarkInSpace(ctx context.Context, portal PortalKey)

func (*User) Scan

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

func (*User) SetLastReadTS added in v0.2.2

func (user *User) SetLastReadTS(ctx context.Context, portal PortalKey, ts time.Time)

func (*User) Update

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

type UserQuery

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

func (*UserQuery) GetAll

func (uq *UserQuery) GetAll(ctx context.Context) ([]*User, error)

func (*UserQuery) GetByMXID

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

func (*UserQuery) GetByUsername added in v0.2.1

func (uq *UserQuery) GetByUsername(ctx context.Context, username string) (*User, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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