Documentation
¶
Overview ¶
Package db implements PostgreSQL-backed storage for teled.
Index ¶
- Variables
- func DecodeDeleted(extra []byte) []int64
- func DecodeRead(extra []byte) (peer, maxID int64)
- func Migrate(uri string) error
- func Open(ctx context.Context, uri string) (*pgxpool.Pool, error)
- type DB
- func (db *DB) BindSession(ctx context.Context, keyID [8]byte, userID int64) error
- func (db *DB) CreateUser(ctx context.Context, phone, firstName, lastName string) (teled.User, error)
- func (db *DB) DeleteMessages(ctx context.Context, self int64, localIDs []int64) (teled.DeleteResult, error)
- func (db *DB) EditMessage(ctx context.Context, self, localID int64, text string) (teled.EditResult, error)
- func (db *DB) FileByID(ctx context.Context, id int64) (teled.File, bool, error)
- func (db *DB) GetDialogs(ctx context.Context, self int64, limit int) ([]teled.Dialog, error)
- func (db *DB) GetDifference(ctx context.Context, self int64, sincePts, limit int) ([]teled.UpdateLogEntry, int, error)
- func (db *DB) GetHistory(ctx context.Context, self, peer, offsetID int64, limit int) ([]teled.Message, error)
- func (db *DB) GetState(ctx context.Context, self int64) (teled.State, error)
- func (db *DB) MessageByGlobal(ctx context.Context, self, globalID int64) (teled.Message, bool, error)
- func (db *DB) PhoneCode(ctx context.Context, phone, codeHash string) (code string, ok bool, err error)
- func (db *DB) ReadHistory(ctx context.Context, self, peer, maxID int64) (pts int, err error)
- func (db *DB) Ready(ctx context.Context) error
- func (db *DB) SaveFile(ctx context.Context, f teled.File) (teled.File, error)
- func (db *DB) SavePhoneCode(ctx context.Context, phone, codeHash, code string, ttl time.Duration) error
- func (db *DB) SendMessage(ctx context.Context, fromID, peerID int64, text string, ...) (teled.SentMessage, error)
- func (db *DB) SessionUserID(ctx context.Context, keyID [8]byte) (userID int64, ok bool, err error)
- func (db *DB) Unbind(ctx context.Context, keyID [8]byte) error
- func (db *DB) UserByID(ctx context.Context, id int64) (*teled.User, bool, error)
- func (db *DB) UserByPhone(ctx context.Context, phone string) (*teled.User, bool, error)
- func (db *DB) UserByUsername(ctx context.Context, username string) (*teled.User, bool, error)
- func (db *DB) UsersByIDs(ctx context.Context, ids []int64) ([]teled.User, error)
- type KeyStore
Constants ¶
This section is empty.
Variables ¶
var ErrMessageID = errors.New("message id invalid")
ErrMessageID indicates a referenced message does not exist or is not editable by the caller.
Functions ¶
func DecodeDeleted ¶
DecodeDeleted extracts deleted local ids from a delete log entry.
func DecodeRead ¶
DecodeRead extracts (peer, maxID) from a read log entry.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is the PostgreSQL-backed storage implementation.
func (*DB) BindSession ¶
BindSession binds an MTProto auth key to a logged-in user.
func (*DB) CreateUser ¶
func (db *DB) CreateUser(ctx context.Context, phone, firstName, lastName string) (teled.User, error)
CreateUser inserts a new user with the given phone and name.
func (*DB) DeleteMessages ¶
func (db *DB) DeleteMessages(ctx context.Context, self int64, localIDs []int64) (teled.DeleteResult, error)
DeleteMessages marks the caller's messages (by local id) deleted and allocates a pts covering them.
func (*DB) EditMessage ¶
func (db *DB) EditMessage(ctx context.Context, self, localID int64, text string) (teled.EditResult, error)
EditMessage updates the text of a message the caller sent, returning the data needed to emit edit updates to both participants.
func (*DB) GetDialogs ¶
GetDialogs returns the caller's conversations, newest activity first.
func (*DB) GetDifference ¶
func (db *DB) GetDifference(ctx context.Context, self int64, sincePts, limit int) ([]teled.UpdateLogEntry, int, error)
GetDifference returns log entries with pts greater than sincePts (up to limit) and the caller's current pts.
func (*DB) GetHistory ¶
func (db *DB) GetHistory(ctx context.Context, self, peer, offsetID int64, limit int) ([]teled.Message, error)
GetHistory returns up to limit messages between self and peer, newest first. When offsetID > 0 only messages with a smaller local id are returned.
func (*DB) MessageByGlobal ¶
func (db *DB) MessageByGlobal(ctx context.Context, self, globalID int64) (teled.Message, bool, error)
MessageByGlobal returns the caller's view of a message by its canonical id.
func (*DB) PhoneCode ¶
func (db *DB) PhoneCode(ctx context.Context, phone, codeHash string) (code string, ok bool, err error)
PhoneCode returns the unexpired code stored for (phone, codeHash).
func (*DB) ReadHistory ¶
ReadHistory marks the caller's incoming messages from peer up to maxID as read and allocates a pts for the read event.
func (*DB) SaveFile ¶
SaveFile records uploaded media, generating an access hash and file reference, and returns the populated File.
func (*DB) SavePhoneCode ¶
func (db *DB) SavePhoneCode(ctx context.Context, phone, codeHash, code string, ttl time.Duration) error
SavePhoneCode stores (or replaces) a login code for phone under codeHash, valid for ttl.
func (*DB) SendMessage ¶
func (db *DB) SendMessage(ctx context.Context, fromID, peerID int64, text string, randomID, mediaFileID int64) (teled.SentMessage, error)
SendMessage persists a DM atomically: the canonical message plus a per-account ref (with its own local id and pts) for sender and recipient. A non-zero mediaFileID attaches stored media so the message re-renders in history.
func (*DB) SessionUserID ¶
SessionUserID returns the user bound to the given auth key, if any.
func (*DB) UserByPhone ¶
UserByPhone returns a user by phone number.
func (*DB) UserByUsername ¶
UserByUsername returns a user by username.
type KeyStore ¶
type KeyStore struct {
// contains filtered or unexported fields
}
KeyStore persists MTProto auth keys, implementing mtproto.KeyStorage.
func NewKeyStore ¶
NewKeyStore creates a KeyStore over the given pool.