db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartCleanInactiveUsers

func StartCleanInactiveUsers(d LoggedDB, each time.Duration, inactivityTimeout time.Duration)

StartCleanInactiveUsers ...

Types

type ChatDB

type ChatDB interface {
	Add(chatname string) error
	Remove(chatname string) error
	GetChats() []string

	AddUser(chatname, username string) error
	RemoveUser(chatname, username string) error
	IsInChat(chatname, username string) bool
	GetUsers(chatname string) []string
}

ChatDB stores chats in-memory

type ChatReport

type ChatReport struct {
	models.User
	models.Chat
	Joined   bool                    `json:"joined"`
	Messages []*models.Message       `json:"messages"`
	Users    []models.UserWithStatus `json:"users"`
}

ChatReport ...

func NewChatReport

func NewChatReport(username, chatname string, joined bool) ChatReport

NewChatReport ...

type LoggedDB

type LoggedDB interface {
	// Login must return valid *User if (error == ErrAlreadyLogged)
	// with other errors must return (nil, err)
	// also should generate valid LoginToken and LastActivity
	Login(username string) (*models.LoggedUser, error)

	Update(*models.LoggedUser) error

	Get(username string) (*models.LoggedUser, error)

	Logout(username string) error

	GetLoggedUsers() []string
}

LoggedDB represents logged users

type MessageDB

type MessageDB interface {
	// should update message ID and time
	Post(*models.Message) error

	// should return empty slice even on error
	GetLastNMessages(chatname string, n int) ([]*models.Message, error)
}

MessageDB ...

type Store

type Store struct {
	UserDB    UserDB
	ChatDB    ChatDB
	LoggedDB  LoggedDB
	MessageDB MessageDB
}

Store contains all databases

func NewStore

func NewStore(u UserDB, c ChatDB, l LoggedDB, m MessageDB) *Store

NewStore ...

func (*Store) MakeChatReportForUser

func (s *Store) MakeChatReportForUser(username string, chatname string) ChatReport

MakeChatReportForUser returns ChatReport for an user. If not joined, Messages and Users fields are always empty. Chat should be locked. LoggedDB, MessageDB should be unlocked.

type UserDB

type UserDB interface {
	Store(u models.FullUser) error
	Update(u models.FullUser) error

	Get(username string) (models.FullUser, error)
}

UserDB should be persistend storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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