store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AccountPairing      = "pairing"
	AccountConnected    = "connected"
	AccountDisconnected = "disconnected"
	AccountLoggedOut    = "logged_out"
)
View Source
const (
	ChatDirect = "direct"
	ChatGroup  = "group"
)
View Source
const (
	GrantStatic = "static"
	GrantOAuth  = "oauth"
)
View Source
const (
	ApprovalElicitation = "elicitation"
	ApprovalApp         = "app"
)
View Source
const (
	MediaPending     = "pending"
	MediaDownloaded  = "downloaded"
	MediaFailed      = "failed"
	MediaUnavailable = "unavailable"
)
View Source
const (
	MessageImage    = "image"
	MessageVideo    = "video"
	MessageAudio    = "audio"
	MessageDocument = "document"
	MessageSticker  = "sticker"
	MessageLocation = "location"
	MessageContact  = "contact"
	MessagePoll     = "poll"
)
View Source
const (
	TokenStatic  = "static"
	TokenAccess  = "access"
	TokenRefresh = "refresh"
)
View Source
const MessageText = "text"
View Source
const RetentionBatch = 1000

Variables

View Source
var (
	ErrNotFound       = errors.New("not found")
	ErrNameInUse      = errors.New("name in use")
	ErrUnknownAccount = errors.New("unknown account")
)

Functions

func ValidApproval

func ValidApproval(mode string) bool

Types

type Account

type Account struct {
	ID              int64
	Name            string
	JID             string
	Phone           string
	ProfileName     string
	Description     string
	RetentionMonths int
	State           string
	CreatedAt       time.Time
}

type AuthCode

type AuthCode struct {
	Hash          string
	ClientID      string
	GrantName     string
	AccountNames  []string
	CodeChallenge string
	RedirectURI   string
	ExpiresAt     time.Time
	CreatedAt     time.Time
}

type Bearer

type Bearer struct {
	Grant     Grant
	ExpiresAt time.Time
}

type Chat

type Chat struct {
	JID           string
	Kind          string
	Name          string
	LastMessageAt time.Time
	UnreadCount   int
}

type ChatCursor

type ChatCursor struct {
	LastMessageAt time.Time
	JID           string
}

type ChatQuery

type ChatQuery struct {
	UnreadOnly bool
	Match      func(Chat) bool
	After      *ChatCursor
	Limit      int
}

type ContactCard

type ContactCard struct {
	Name  string `json:"name"`
	VCard string `json:"vcard"`
}

type Details

type Details struct {
	Poll     *Poll         `json:"poll,omitempty"`
	Location *Location     `json:"location,omitempty"`
	Contacts []ContactCard `json:"contacts,omitempty"`
}

type ExpiredBatch

type ExpiredBatch struct {
	Messages int
	Files    int
}

type Grant

type Grant struct {
	ID        int64
	ClientID  string
	Name      string
	Kind      string
	ReadOnly  bool
	Approval  string
	CreatedAt time.Time
	RevokedAt time.Time
}

func (Grant) Revoked

func (g Grant) Revoked() bool

func (Grant) TrustsApp

func (g Grant) TrustsApp() bool

type GrantChange

type GrantChange struct {
	Name                string
	ChangeAccounts      bool
	AllExistingAccounts bool
	AccountNames        []string
	Approval            string
}

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	Name      string  `json:"name,omitempty"`
	Address   string  `json:"address,omitempty"`
	URL       string  `json:"url,omitempty"`
	Live      bool    `json:"live,omitempty"`
}

type Media

type Media struct {
	Mime          string
	FileName      string
	Size          int64
	Seconds       int
	VoiceNote     bool
	MediaKey      []byte
	DirectPath    string
	FileSHA256    []byte
	FileEncSHA256 []byte
	State         string
	Path          string
}

type MediaFailure

type MediaFailure struct {
	State    string
	Attempts int
	Error    string
	RetryAt  time.Time
}

type MediaFile

type MediaFile struct {
	MediaRef
	Kind     string
	Media    Media
	SentAt   time.Time
	Path     string
	Attempts int
	Error    string
	RetryAt  time.Time
}

type MediaRef

type MediaRef struct {
	AccountID int64
	ChatJID   string
	MessageID string
}

type Message

type Message struct {
	ChatJID    string
	ID         string
	SenderJID  string
	SenderName string
	FromMe     bool
	SentAt     time.Time
	Kind       string
	Text       string
	QuotedID   string
	EditedAt   time.Time
	RevokedAt  time.Time
	Media      *Media
	Details    *Details
	Reactions  []Reaction
}

type MessageBound

type MessageBound struct {
	SentAt time.Time
	ID     string
}

type MessageQuery

type MessageQuery struct {
	Before *MessageBound
	After  *MessageBound
	Limit  int
}

type NewAccount

type NewAccount struct {
	Name        string
	Phone       string
	Description string
	CreatedAt   time.Time
}

type NewGrant

type NewGrant struct {
	ClientID            string
	Name                string
	Kind                string
	ReadOnly            bool
	Approval            string
	AllExistingAccounts bool
	AccountNames        []string
	CreatedAt           time.Time
	Tokens              []Token
}

type OAuthClient

type OAuthClient struct {
	ID           string
	Name         string
	RedirectURIs []string
	AuthMethod   string
	SecretHash   string
	CreatedAt    time.Time
}

type PhoneInUseError

type PhoneInUseError struct {
	Phone   string
	Account string
}

func (*PhoneInUseError) Error

func (e *PhoneInUseError) Error() string

type Poll

type Poll struct {
	Options    []string `json:"options"`
	MaxChoices int      `json:"max_choices"`
}

type Reaction

type Reaction struct {
	ChatJID    string
	MessageID  string
	SenderJID  string
	SenderName string
	FromMe     bool
	Emoji      string
	ReactedAt  time.Time
}

type ReusedError

type ReusedError struct {
	Grant Grant
}

func (*ReusedError) Error

func (e *ReusedError) Error() string

type SearchPosition

type SearchPosition struct {
	SentAt  time.Time
	ChatJID string
	ID      string
}

type SearchQuery

type SearchQuery struct {
	Match   string
	ChatJID string
	Since   time.Time
	Until   time.Time
	Before  *SearchPosition
	Limit   int
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(ctx context.Context, path string) (*Store, error)

func (*Store) Account

func (s *Store) Account(ctx context.Context, id int64) (Account, error)

func (*Store) AccountByName

func (s *Store) AccountByName(ctx context.Context, name string) (Account, error)

func (*Store) ActiveGrant

func (s *Store) ActiveGrant(ctx context.Context, id int64) (Grant, error)

func (*Store) ChangeGrant

func (s *Store) ChangeGrant(ctx context.Context, c GrantChange) (Grant, error)

func (*Store) Chat

func (s *Store) Chat(ctx context.Context, accountID int64, jid string) (Chat, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CountMessages

func (s *Store) CountMessages(ctx context.Context, accountID int64) (int64, error)

func (*Store) CreateAccount

func (s *Store) CreateAccount(ctx context.Context, n NewAccount) (Account, error)

func (*Store) CreateAuthCode

func (s *Store) CreateAuthCode(ctx context.Context, c AuthCode) error

func (*Store) CreateGrant

func (s *Store) CreateGrant(ctx context.Context, n NewGrant) (Grant, error)

func (*Store) CreateOAuthClient

func (s *Store) CreateOAuthClient(ctx context.Context, c OAuthClient) error

func (*Store) DeleteAccount

func (s *Store) DeleteAccount(ctx context.Context, id int64) error

func (*Store) DeleteMessagesBefore

func (s *Store) DeleteMessagesBefore(ctx context.Context, accountID int64, before time.Time, removeFiles func(paths []string) error) (ExpiredBatch, error)

func (*Store) DeleteUnfinishedPairings

func (s *Store) DeleteUnfinishedPairings(ctx context.Context) error

func (*Store) DueMedia

func (s *Store) DueMedia(ctx context.Context, now time.Time, limit int) ([]MediaFile, error)

func (*Store) EditMessage

func (s *Store) EditMessage(ctx context.Context, accountID int64, chatJID, id, senderJID, text string, editedAt time.Time) error

func (*Store) ForgetUnusedOAuthClients

func (s *Store) ForgetUnusedOAuthClients(ctx context.Context, registeredBefore, now time.Time) error

func (*Store) Grant

func (s *Store) Grant(ctx context.Context, id int64) (Grant, error)

func (*Store) GrantAccounts

func (s *Store) GrantAccounts(ctx context.Context, g Grant) ([]Account, error)

func (*Store) GrantByName

func (s *Store) GrantByName(ctx context.Context, name string) (Grant, error)

func (*Store) GrantForBearer

func (s *Store) GrantForBearer(ctx context.Context, hash string, now time.Time) (Bearer, error)

func (*Store) HasMessages

func (s *Store) HasMessages(ctx context.Context, accountID int64, chatJID string, q MessageQuery) (bool, error)

func (*Store) InsertToken

func (s *Store) InsertToken(ctx context.Context, t Token) error

func (*Store) ListAccounts

func (s *Store) ListAccounts(ctx context.Context) ([]Account, error)

func (*Store) ListChats

func (s *Store) ListChats(ctx context.Context, accountID int64, q ChatQuery) ([]Chat, error)

func (*Store) ListGrants

func (s *Store) ListGrants(ctx context.Context) ([]Grant, error)

func (*Store) MarkChatReadUntil

func (s *Store) MarkChatReadUntil(ctx context.Context, accountID int64, jid string, readAt time.Time) error

func (*Store) MediaFile

func (s *Store) MediaFile(ctx context.Context, ref MediaRef) (MediaFile, error)

func (*Store) MediaFileByPath

func (s *Store) MediaFileByPath(ctx context.Context, path string) (MediaFile, error)

func (*Store) MergeIdentity

func (s *Store) MergeIdentity(ctx context.Context, accountID int64, lid, phone string) error

func (*Store) Message

func (s *Store) Message(ctx context.Context, accountID int64, chatJID, id string) (Message, error)

func (*Store) Messages

func (s *Store) Messages(ctx context.Context, accountID int64, chatJID string, q MessageQuery) ([]Message, error)

func (*Store) OAuthClient

func (s *Store) OAuthClient(ctx context.Context, id string) (OAuthClient, error)

func (*Store) OldestMessage

func (s *Store) OldestMessage(ctx context.Context, accountID int64, chatJID string) (Message, error)

func (*Store) React

func (s *Store) React(ctx context.Context, accountID int64, r Reaction) error

func (*Store) RedeemAuthCode

func (s *Store) RedeemAuthCode(ctx context.Context, hash string, now time.Time, issue func(AuthCode) (NewGrant, error)) (Grant, error)

func (*Store) RetryFailedMediaNow

func (s *Store) RetryFailedMediaNow(ctx context.Context, accountID int64, now time.Time) error

func (*Store) RevokeGrant

func (s *Store) RevokeGrant(ctx context.Context, name string, at time.Time) (Grant, error)

func (*Store) RevokeGrantOfToken

func (s *Store) RevokeGrantOfToken(ctx context.Context, hash string, at time.Time, allowed func(Grant) bool) (Grant, error)

func (*Store) RevokeMessage

func (s *Store) RevokeMessage(ctx context.Context, accountID int64, chatJID, id, senderJID string, byAdmin bool, revokedAt time.Time) error

func (*Store) RotateRefreshToken

func (s *Store) RotateRefreshToken(ctx context.Context, hash string, now time.Time, issue func(Grant) ([]Token, error)) (Grant, error)

func (*Store) SaveChat

func (s *Store) SaveChat(ctx context.Context, accountID int64, chat Chat) error

func (*Store) SaveHistoryMessage

func (s *Store) SaveHistoryMessage(ctx context.Context, accountID int64, chat Chat, msg Message) error

func (*Store) SaveMessage

func (s *Store) SaveMessage(ctx context.Context, accountID int64, chat Chat, msg Message) error

func (*Store) SearchMessages

func (s *Store) SearchMessages(ctx context.Context, accountID int64, q SearchQuery) ([]Message, error)

func (*Store) SetAccountDescription

func (s *Store) SetAccountDescription(ctx context.Context, name, description string) (Account, error)

func (*Store) SetAccountLoggedOut

func (s *Store) SetAccountLoggedOut(ctx context.Context, id int64) error

func (*Store) SetAccountPaired

func (s *Store) SetAccountPaired(ctx context.Context, id int64, jid, phone string) error

func (*Store) SetAccountProfileName

func (s *Store) SetAccountProfileName(ctx context.Context, id int64, name string) error

func (*Store) SetAccountRetention

func (s *Store) SetAccountRetention(ctx context.Context, name string, months int) (Account, error)

func (*Store) SetAccountState

func (s *Store) SetAccountState(ctx context.Context, id int64, state string) error

func (*Store) SetChatName

func (s *Store) SetChatName(ctx context.Context, accountID int64, jid, name string) error

func (*Store) SetMediaDownloaded

func (s *Store) SetMediaDownloaded(ctx context.Context, ref MediaRef, path string) (bool, error)

func (*Store) SetMediaFailed

func (s *Store) SetMediaFailed(ctx context.Context, ref MediaRef, failure MediaFailure) error

func (*Store) SetUnreadCount

func (s *Store) SetUnreadCount(ctx context.Context, accountID int64, jid string, count int) error

func (*Store) SpendApproval

func (s *Store) SpendApproval(ctx context.Context, nonce string, expires, now time.Time) (bool, error)

type Token

type Token struct {
	Hash      string
	GrantID   int64
	Kind      string
	ExpiresAt time.Time
	CreatedAt time.Time
}

type UnknownAccountError

type UnknownAccountError struct {
	Name string
}

func (*UnknownAccountError) Error

func (e *UnknownAccountError) Error() string

func (*UnknownAccountError) Is

func (e *UnknownAccountError) Is(target error) bool

Jump to

Keyboard shortcuts

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