database

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const SqliteEnabled = true

Variables

This section is empty.

Functions

func GetNick

func GetNick(user *User, net *Network) string

func GetRealname

func GetRealname(user *User, net *Network) string

func GetUsername

func GetUsername(user *User, net *Network) string

Types

type Channel

type Channel struct {
	ID   int64
	Name string
	Key  string

	Detached              bool
	DetachedInternalMsgID string

	RelayDetached MessageFilter
	ReattachOn    MessageFilter
	DetachAfter   time.Duration
	DetachOn      MessageFilter
}

type Database

type Database interface {
	Close() error
	Stats(ctx context.Context) (*DatabaseStats, error)

	ListUsers(ctx context.Context) ([]User, error)
	GetUser(ctx context.Context, username string) (*User, error)
	StoreUser(ctx context.Context, user *User) error
	DeleteUser(ctx context.Context, id int64) error
	ListInactiveUsernames(ctx context.Context, limit time.Time) ([]string, error)

	ListNetworks(ctx context.Context, userID int64) ([]Network, error)
	StoreNetwork(ctx context.Context, userID int64, network *Network) error
	DeleteNetwork(ctx context.Context, id int64) error
	ListChannels(ctx context.Context, networkID int64) ([]Channel, error)
	StoreChannel(ctx context.Context, networKID int64, ch *Channel) error
	DeleteChannel(ctx context.Context, id int64) error

	ListDeliveryReceipts(ctx context.Context, networkID int64) ([]DeliveryReceipt, error)
	StoreClientDeliveryReceipts(ctx context.Context, networkID int64, client string, receipts []DeliveryReceipt) error

	GetReadReceipt(ctx context.Context, networkID int64, name string) (*ReadReceipt, error)
	StoreReadReceipt(ctx context.Context, networkID int64, receipt *ReadReceipt) error

	ListWebPushConfigs(ctx context.Context) ([]WebPushConfig, error)
	StoreWebPushConfig(ctx context.Context, config *WebPushConfig) error

	ListWebPushSubscriptions(ctx context.Context, userID, networkID int64) ([]WebPushSubscription, error)
	StoreWebPushSubscription(ctx context.Context, userID, networkID int64, sub *WebPushSubscription) error
	DeleteWebPushSubscription(ctx context.Context, id int64) error

	GetMessageLastID(ctx context.Context, networkID int64, name string) (int64, error)
	StoreMessages(ctx context.Context, networkID int64, name string, msgs []*irc.Message) ([]int64, error)
	ListMessageLastPerTarget(ctx context.Context, networkID int64, options *MessageOptions) ([]MessageTarget, error)
	ListMessages(ctx context.Context, networkID int64, name string, options *MessageOptions) ([]*irc.Message, error)
}

func Open

func Open(driver, source string) (Database, error)

func OpenPostgresDB

func OpenPostgresDB(source string) (Database, error)

func OpenSqliteDB

func OpenSqliteDB(source string) (Database, error)

func OpenTempPostgresDB

func OpenTempPostgresDB(source string) (Database, error)

func OpenTempSqliteDB

func OpenTempSqliteDB() (Database, error)

type DatabaseStats

type DatabaseStats struct {
	Users    int64
	Networks int64
	Channels int64
}

type DeliveryReceipt

type DeliveryReceipt struct {
	ID            int64
	Target        string // channel or nick
	Client        string
	InternalMsgID string
}

type MessageFilter

type MessageFilter int
const (
	// TODO: use customizable user defaults for FilterDefault
	FilterDefault MessageFilter = iota
	FilterNone
	FilterHighlight
	FilterMessage
)

type MessageOptions added in v0.6.0

type MessageOptions struct {
	AfterID    int64
	AfterTime  time.Time
	BeforeTime time.Time
	Limit      int
	Events     bool
	Sender     string
	Text       string
	TakeLast   bool
}

type MessageTarget added in v0.6.0

type MessageTarget struct {
	Name          string
	LatestMessage time.Time
}

type MetricsCollectorDatabase

type MetricsCollectorDatabase interface {
	Database
	RegisterMetrics(r prometheus.Registerer) error
}

type Network

type Network struct {
	ID              int64
	Name            string
	Addr            string
	Nick            string
	Username        string
	Realname        string
	Pass            string
	ConnectCommands []string
	CertFP          string
	SASL            SASL
	AutoAway        bool
	Enabled         bool
}

func NewNetwork added in v0.7.0

func NewNetwork(addr string) *Network

func (*Network) GetName

func (net *Network) GetName() string

func (*Network) URL

func (net *Network) URL() (*url.URL, error)

type PostgresDB

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

func (*PostgresDB) Close

func (db *PostgresDB) Close() error

func (*PostgresDB) DeleteChannel

func (db *PostgresDB) DeleteChannel(ctx context.Context, id int64) error

func (*PostgresDB) DeleteNetwork

func (db *PostgresDB) DeleteNetwork(ctx context.Context, id int64) error

func (*PostgresDB) DeleteUser

func (db *PostgresDB) DeleteUser(ctx context.Context, id int64) error

func (*PostgresDB) DeleteWebPushSubscription

func (db *PostgresDB) DeleteWebPushSubscription(ctx context.Context, id int64) error

func (*PostgresDB) GetMessageLastID added in v0.6.0

func (db *PostgresDB) GetMessageLastID(ctx context.Context, networkID int64, name string) (int64, error)

func (*PostgresDB) GetReadReceipt

func (db *PostgresDB) GetReadReceipt(ctx context.Context, networkID int64, name string) (*ReadReceipt, error)

func (*PostgresDB) GetUser

func (db *PostgresDB) GetUser(ctx context.Context, username string) (*User, error)

func (*PostgresDB) ListChannels

func (db *PostgresDB) ListChannels(ctx context.Context, networkID int64) ([]Channel, error)

func (*PostgresDB) ListDeliveryReceipts

func (db *PostgresDB) ListDeliveryReceipts(ctx context.Context, networkID int64) ([]DeliveryReceipt, error)

func (*PostgresDB) ListInactiveUsernames added in v0.6.0

func (db *PostgresDB) ListInactiveUsernames(ctx context.Context, limit time.Time) ([]string, error)

func (*PostgresDB) ListMessageLastPerTarget added in v0.6.0

func (db *PostgresDB) ListMessageLastPerTarget(ctx context.Context, networkID int64, options *MessageOptions) ([]MessageTarget, error)

func (*PostgresDB) ListMessages added in v0.6.0

func (db *PostgresDB) ListMessages(ctx context.Context, networkID int64, name string, options *MessageOptions) ([]*irc.Message, error)

func (*PostgresDB) ListNetworks

func (db *PostgresDB) ListNetworks(ctx context.Context, userID int64) ([]Network, error)

func (*PostgresDB) ListUsers

func (db *PostgresDB) ListUsers(ctx context.Context) ([]User, error)

func (*PostgresDB) ListWebPushConfigs

func (db *PostgresDB) ListWebPushConfigs(ctx context.Context) ([]WebPushConfig, error)

func (*PostgresDB) ListWebPushSubscriptions

func (db *PostgresDB) ListWebPushSubscriptions(ctx context.Context, userID, networkID int64) ([]WebPushSubscription, error)

func (*PostgresDB) RegisterMetrics

func (db *PostgresDB) RegisterMetrics(r prometheus.Registerer) error

func (*PostgresDB) Stats

func (db *PostgresDB) Stats(ctx context.Context) (*DatabaseStats, error)

func (*PostgresDB) StoreChannel

func (db *PostgresDB) StoreChannel(ctx context.Context, networkID int64, ch *Channel) error

func (*PostgresDB) StoreClientDeliveryReceipts

func (db *PostgresDB) StoreClientDeliveryReceipts(ctx context.Context, networkID int64, client string, receipts []DeliveryReceipt) error

func (*PostgresDB) StoreMessages added in v0.7.0

func (db *PostgresDB) StoreMessages(ctx context.Context, networkID int64, name string, msgs []*irc.Message) ([]int64, error)

func (*PostgresDB) StoreNetwork

func (db *PostgresDB) StoreNetwork(ctx context.Context, userID int64, network *Network) error

func (*PostgresDB) StoreReadReceipt

func (db *PostgresDB) StoreReadReceipt(ctx context.Context, networkID int64, receipt *ReadReceipt) error

func (*PostgresDB) StoreUser

func (db *PostgresDB) StoreUser(ctx context.Context, user *User) error

func (*PostgresDB) StoreWebPushConfig

func (db *PostgresDB) StoreWebPushConfig(ctx context.Context, config *WebPushConfig) error

func (*PostgresDB) StoreWebPushSubscription

func (db *PostgresDB) StoreWebPushSubscription(ctx context.Context, userID, networkID int64, sub *WebPushSubscription) error

type ReadReceipt

type ReadReceipt struct {
	ID        int64
	Target    string // channel or nick
	Timestamp time.Time
}

type SASL

type SASL struct {
	Mechanism string

	Plain struct {
		Username string
		Password string
	}

	// TLS client certificate authentication.
	External struct {
		// X.509 certificate in DER form.
		CertBlob []byte
		// PKCS#8 private key in DER form.
		PrivKeyBlob []byte
	}
}

type SqliteDB

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

func (*SqliteDB) Close

func (db *SqliteDB) Close() error

func (*SqliteDB) DeleteChannel

func (db *SqliteDB) DeleteChannel(ctx context.Context, id int64) error

func (*SqliteDB) DeleteNetwork

func (db *SqliteDB) DeleteNetwork(ctx context.Context, id int64) error

func (*SqliteDB) DeleteUser

func (db *SqliteDB) DeleteUser(ctx context.Context, id int64) error

func (*SqliteDB) DeleteWebPushSubscription

func (db *SqliteDB) DeleteWebPushSubscription(ctx context.Context, id int64) error

func (*SqliteDB) GetMessageLastID added in v0.6.0

func (db *SqliteDB) GetMessageLastID(ctx context.Context, networkID int64, name string) (int64, error)

func (*SqliteDB) GetReadReceipt

func (db *SqliteDB) GetReadReceipt(ctx context.Context, networkID int64, name string) (*ReadReceipt, error)

func (*SqliteDB) GetUser

func (db *SqliteDB) GetUser(ctx context.Context, username string) (*User, error)

func (*SqliteDB) ListChannels

func (db *SqliteDB) ListChannels(ctx context.Context, networkID int64) ([]Channel, error)

func (*SqliteDB) ListDeliveryReceipts

func (db *SqliteDB) ListDeliveryReceipts(ctx context.Context, networkID int64) ([]DeliveryReceipt, error)

func (*SqliteDB) ListInactiveUsernames added in v0.6.0

func (db *SqliteDB) ListInactiveUsernames(ctx context.Context, limit time.Time) ([]string, error)

func (*SqliteDB) ListMessageLastPerTarget added in v0.6.0

func (db *SqliteDB) ListMessageLastPerTarget(ctx context.Context, networkID int64, options *MessageOptions) ([]MessageTarget, error)

func (*SqliteDB) ListMessages added in v0.6.0

func (db *SqliteDB) ListMessages(ctx context.Context, networkID int64, name string, options *MessageOptions) ([]*irc.Message, error)

func (*SqliteDB) ListNetworks

func (db *SqliteDB) ListNetworks(ctx context.Context, userID int64) ([]Network, error)

func (*SqliteDB) ListUsers

func (db *SqliteDB) ListUsers(ctx context.Context) ([]User, error)

func (*SqliteDB) ListWebPushConfigs

func (db *SqliteDB) ListWebPushConfigs(ctx context.Context) ([]WebPushConfig, error)

func (*SqliteDB) ListWebPushSubscriptions

func (db *SqliteDB) ListWebPushSubscriptions(ctx context.Context, userID, networkID int64) ([]WebPushSubscription, error)

func (*SqliteDB) RegisterMetrics

func (db *SqliteDB) RegisterMetrics(r prometheus.Registerer) error

func (*SqliteDB) Stats

func (db *SqliteDB) Stats(ctx context.Context) (*DatabaseStats, error)

func (*SqliteDB) StoreChannel

func (db *SqliteDB) StoreChannel(ctx context.Context, networkID int64, ch *Channel) error

func (*SqliteDB) StoreClientDeliveryReceipts

func (db *SqliteDB) StoreClientDeliveryReceipts(ctx context.Context, networkID int64, client string, receipts []DeliveryReceipt) error

func (*SqliteDB) StoreMessages added in v0.7.0

func (db *SqliteDB) StoreMessages(ctx context.Context, networkID int64, name string, msgs []*irc.Message) ([]int64, error)

func (*SqliteDB) StoreNetwork

func (db *SqliteDB) StoreNetwork(ctx context.Context, userID int64, network *Network) error

func (*SqliteDB) StoreReadReceipt

func (db *SqliteDB) StoreReadReceipt(ctx context.Context, networkID int64, receipt *ReadReceipt) error

func (*SqliteDB) StoreUser

func (db *SqliteDB) StoreUser(ctx context.Context, user *User) error

func (*SqliteDB) StoreWebPushConfig

func (db *SqliteDB) StoreWebPushConfig(ctx context.Context, config *WebPushConfig) error

func (*SqliteDB) StoreWebPushSubscription

func (db *SqliteDB) StoreWebPushSubscription(ctx context.Context, userID, networkID int64, sub *WebPushSubscription) error

type User

type User struct {
	ID                     int64
	Username               string
	Password               string // hashed
	Nick                   string
	Realname               string
	Admin                  bool
	Enabled                bool
	DownstreamInteractedAt time.Time
}

func NewUser added in v0.7.0

func NewUser(username string) *User

func (*User) CheckPassword

func (u *User) CheckPassword(password string) (upgraded bool, err error)

func (*User) SetPassword

func (u *User) SetPassword(password string) error

type WebPushConfig

type WebPushConfig struct {
	ID        int64
	VAPIDKeys struct {
		Public, Private string
	}
}

type WebPushSubscription

type WebPushSubscription struct {
	ID                   int64
	Endpoint             string
	CreatedAt, UpdatedAt time.Time // read-only

	Keys struct {
		Auth   string
		P256DH string
		VAPID  string
	}
}

Jump to

Keyboard shortcuts

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