dispatch/storage/storage.go

76 lines
1.9 KiB
Go
Raw Normal View History

package storage
import (
2019-01-27 07:53:07 +00:00
"errors"
"os"
"github.com/khlieng/dispatch/pkg/session"
)
var (
Path directory
GetMessageStore MessageStoreCreator
GetMessageSearchProvider MessageSearchProviderCreator
)
2020-04-20 01:02:15 +00:00
func Initialize(root, dataRoot, configRoot string) {
if root != DefaultDirectory() {
Path.dataRoot = root
Path.configRoot = root
} else {
2020-04-20 01:02:15 +00:00
Path.dataRoot = dataRoot
Path.configRoot = configRoot
}
2020-04-20 01:02:15 +00:00
os.MkdirAll(Path.DataRoot(), 0700)
os.MkdirAll(Path.ConfigRoot(), 0700)
2016-01-07 22:59:38 +00:00
}
2019-01-27 07:53:07 +00:00
var (
ErrNotFound = errors.New("no item found")
)
type Store interface {
2020-06-15 08:58:51 +00:00
Users() ([]*User, error)
SaveUser(user *User) error
DeleteUser(user *User) error
2020-06-15 08:58:51 +00:00
Network(user *User, host string) (*Network, error)
Networks(user *User) ([]*Network, error)
SaveNetwork(user *User, network *Network) error
RemoveNetwork(user *User, host string) error
2020-06-15 08:58:51 +00:00
Channels(user *User) ([]*Channel, error)
HasChannel(user *User, network, channel string) bool
SaveChannel(user *User, channel *Channel) error
RemoveChannel(user *User, network, channel string) error
2020-06-15 08:58:51 +00:00
OpenDMs(user *User) ([]Tab, error)
AddOpenDM(user *User, network, nick string) error
RemoveOpenDM(user *User, network, nick string) error
}
type SessionStore interface {
2020-06-15 08:58:51 +00:00
Sessions() ([]*session.Session, error)
SaveSession(session *session.Session) error
DeleteSession(key string) error
}
type MessageStore interface {
LogMessage(message *Message) error
LogMessages(messages []*Message) error
2020-06-15 08:58:51 +00:00
Messages(network, channel string, count int, fromID string) ([]Message, bool, error)
MessagesByID(network, channel string, ids []string) ([]Message, error)
Close()
}
type MessageStoreCreator func(*User) (MessageStore, error)
type MessageSearchProvider interface {
2020-06-15 08:58:51 +00:00
SearchMessages(network, channel, q string) ([]string, error)
Index(id string, message *Message) error
Close()
}
type MessageSearchProviderCreator func(*User) (MessageSearchProvider, error)