storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextId

func NextId() string

Types

type PersistentStorage

type PersistentStorage interface {
	Close() error

	GetAllRooms(ctx context.Context) ([]*StoredRoom, error)
	GetRoom(ctx context.Context, roomId string) (*StoredRoom, error)
	UpsertRoom(ctx context.Context, room *StoredRoom) error
	DeleteRoom(ctx context.Context, roomId string) error

	GetEventResult(ctx context.Context, eventId string) (*StoredEventResult, error)
	UpsertEventResult(ctx context.Context, event *StoredEventResult) error

	// GetUserIdsAndDisplayNamesByRoomId - returns (userIds, displayNames, error) for user IDs joined to the room.
	// Values are deduplicated.
	GetUserIdsAndDisplayNamesByRoomId(ctx context.Context, roomId string) ([]string, []string, error)
	// SetUserIdsAndDisplayNamesByRoomId - replaces the stored user IDs and display names for a given room. The supplied
	// slices MUST be the same length, and ordered against the user IDs slice.
	SetUserIdsAndDisplayNamesByRoomId(ctx context.Context, roomId string, userIds []string, displayNames []string) error

	IsUserBannedInList(ctx context.Context, listRoomId string, userId string) (bool, error)
	// SetListBanRules - sets the listRoomId's ban rules to the entityToEntityType map.
	// Example entityToEntityMap: {"@user:example.org":"m.policy.rule.user"}
	SetListBanRules(ctx context.Context, listRoomId string, entityToEntityType map[string]string) error

	CreateCommunity(ctx context.Context, name string) (*StoredCommunity, error)
	UpsertCommunity(ctx context.Context, community *StoredCommunity) error
	GetCommunity(ctx context.Context, id string) (*StoredCommunity, error)

	// PopStateLearnQueue - returns the next item in the state learn queue, or nil if the queue is empty.
	// The caller is responsible for calling Commit() on the returned Transaction, completing the operation.
	PopStateLearnQueue(ctx context.Context) (*StateLearnQueueItem, Transaction, error)
	PushStateLearnQueue(ctx context.Context, item *StateLearnQueueItem) error

	// SetTrustData - stores arbitrary "trust" data under a given key. The key is scoped to the sourceName, and may be
	// an empty string. The data is stored as JSON and must be serializable.
	SetTrustData(ctx context.Context, sourceName string, key string, data any) error
	GetTrustData(ctx context.Context, sourceName string, key string, result any) error
}

type PostgresStorage

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

func NewPostgresStorage

func NewPostgresStorage(config *PostgresStorageConfig) (*PostgresStorage, error)

func (*PostgresStorage) Close

func (s *PostgresStorage) Close() error

func (*PostgresStorage) CreateCommunity

func (s *PostgresStorage) CreateCommunity(ctx context.Context, name string) (*StoredCommunity, error)

func (*PostgresStorage) DeleteRoom

func (s *PostgresStorage) DeleteRoom(ctx context.Context, roomId string) error

func (*PostgresStorage) GetAllRooms

func (s *PostgresStorage) GetAllRooms(ctx context.Context) ([]*StoredRoom, error)

func (*PostgresStorage) GetCommunity

func (s *PostgresStorage) GetCommunity(ctx context.Context, communityId string) (*StoredCommunity, error)

func (*PostgresStorage) GetEventResult

func (s *PostgresStorage) GetEventResult(ctx context.Context, eventId string) (*StoredEventResult, error)

func (*PostgresStorage) GetRoom

func (s *PostgresStorage) GetRoom(ctx context.Context, roomId string) (*StoredRoom, error)

func (*PostgresStorage) GetTrustData

func (s *PostgresStorage) GetTrustData(ctx context.Context, sourceName string, key string, data any) error

func (*PostgresStorage) GetUserIdsAndDisplayNamesByRoomId

func (s *PostgresStorage) GetUserIdsAndDisplayNamesByRoomId(ctx context.Context, roomId string) ([]string, []string, error)

func (*PostgresStorage) IsUserBannedInList

func (s *PostgresStorage) IsUserBannedInList(ctx context.Context, listRoomId string, userId string) (bool, error)

func (*PostgresStorage) PopStateLearnQueue

func (s *PostgresStorage) PopStateLearnQueue(ctx context.Context) (*StateLearnQueueItem, Transaction, error)

func (*PostgresStorage) PushStateLearnQueue

func (s *PostgresStorage) PushStateLearnQueue(ctx context.Context, item *StateLearnQueueItem) error

func (*PostgresStorage) SendNotify

func (s *PostgresStorage) SendNotify(ctx context.Context, channel string, msg string) error

func (*PostgresStorage) SetListBanRules

func (s *PostgresStorage) SetListBanRules(ctx context.Context, listRoomId string, entityToEntityType map[string]string) error

func (*PostgresStorage) SetTrustData

func (s *PostgresStorage) SetTrustData(ctx context.Context, sourceName string, key string, data any) error

func (*PostgresStorage) SetUserIdsAndDisplayNamesByRoomId

func (s *PostgresStorage) SetUserIdsAndDisplayNamesByRoomId(ctx context.Context, roomId string, userIds []string, displayNames []string) error

func (*PostgresStorage) UpsertCommunity

func (s *PostgresStorage) UpsertCommunity(ctx context.Context, community *StoredCommunity) error

func (*PostgresStorage) UpsertEventResult

func (s *PostgresStorage) UpsertEventResult(ctx context.Context, event *StoredEventResult) error

func (*PostgresStorage) UpsertRoom

func (s *PostgresStorage) UpsertRoom(ctx context.Context, room *StoredRoom) error

type PostgresStorageConfig

type PostgresStorageConfig struct {
	// Read/Write Database connection config
	RWDatabase *PostgresStorageConnectionConfig
	// Readonly Database connection config. If nil, the RW database will be used for RO operations
	RODatabase *PostgresStorageConnectionConfig
	// File path to the directory containing migrations
	MigrationsPath string
}

type PostgresStorageConnectionConfig

type PostgresStorageConnectionConfig struct {
	Uri          string
	MaxOpenConns int
	MaxIdleConns int
}

type StateLearnQueueItem

type StateLearnQueueItem struct {
	RoomId               string
	AtEventId            string
	ViaServer            string
	AfterTimestampMillis int64
}

type StoredCommunity

type StoredCommunity struct {
	CommunityId string                  `json:"community_id"`
	Name        string                  `json:"name"`
	Config      *config.CommunityConfig `json:"config"`
}

type StoredEventResult

type StoredEventResult struct {
	EventId           string             `json:"event_id"`
	IsProbablySpam    bool               `json:"is_probably_spam"`
	ConfidenceVectors confidence.Vectors `json:"confidence_vectors"`
}

type StoredRoom

type StoredRoom struct {
	RoomId                         string `json:"room_id"`
	RoomVersion                    string `json:"room_version"`
	ModeratorUserId                string `json:"moderator_user_id"` // TODO: Drop
	LastCachedStateTimestampMillis int64  `json:"last_cached_state_timestamp"`
	CommunityId                    string `json:"community_id"`
}

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error
}

Jump to

Keyboard shortcuts

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