convo

package
v0.0.0-...-a17a3e0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ConvoMessage int = 1
View Source
const Frequency = 1 * time.Second

Frequency is the frequency with which the Scribe writes to the log.

View Source
const MaxBuffer = 128

MaxBuffer is the maximum number of messages which will be buffered before writing them to disk.

Variables

View Source
var (
	ConvoBucket   = store.Bucket("convos")
	ScribeBucket  = store.Bucket("scribes")
	MessageBucket = store.Bucket("messages")
)

Bucket constants.

Functions

func CheckExists

func CheckExists(id string) func(*bolt.Tx) error

CheckExists returns a function which returns nil if the Convo with the given ID exists.

func CheckNotExist

func CheckNotExist(id string) func(*bolt.Tx) error

CheckNotExist returns a function which returns nil if the Convo with the given ID does not exist.

func Delete

func Delete(id []byte) func(tx *bolt.Tx) error

Delete deletes the convo with the given ID.

func DeleteMessages

func DeleteMessages(id string) func(*bolt.Tx) error

DeleteMessages deletes a Message bucket. Don't use this until the Scribe has been hung up.

func Get

func Get(c *Convo, id string) func(*bolt.Tx) error

Get returns a function which loads the convo for the given ID, or returns any error.

func GetAll

func GetAll(
	user string,
	filters ...users.Filter,
) func(*bolt.Tx) ([]*Convo, error)

GetAll returns a function which unmarshals all convos for which the user has ownership. If Filters are passed, only convos for which filter.Member(convo) == true will be returned.

func InitMessages

func InitMessages(id string) func(*bolt.Tx) error

InitMessages initializes a Message bucket for the given Stream ID.

func IsExists

func IsExists(err error) bool

func IsMissing

func IsMissing(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func Upsert

func Upsert(c *Convo) func(tx *bolt.Tx) error

Upsert inserts or updates a Convo in the database. It should already have an ID set using something like uuid.NewV4.

Types

type Connected

type Connected ConnectionNotif

Connected is a ConnectionNotif for convo connection events

func (Connected) Resource

func (Connected) Resource() store.Resource

Resource implements Resourcer.Resource on Connected.

type ConnectionNotif

type ConnectionNotif struct {
	UserID  string `json:"userID"`
	ConvoID string `json:"convoID"`
}

ConnectionNotif is a base for convo Resourcers to create notifs. Implement store.Resourcer as a method on an alias of ConnectionNotif.

type Convo

type Convo stream.Stream

Convo is an alias for stream.Stream, i.e., it is a struct for controlling access and ownership of a websocket based connection.

func (*Convo) Connected

func (c *Convo) Connected(user string) store.Resourcer

Connected returns a store.Resourcer which can notify that a user has connected.

func (*Convo) Disconnected

func (c *Convo) Disconnected(user string) store.Resourcer

Disconnected returns a store.Resourcer which can notify that a user has disconnected.

func (Convo) Resource

func (Convo) Resource() store.Resource

Resource implements Resourcer.Resource on Convo.

type Deleted

type Deleted string

Deleted is a Resourcer which can notify that the convo has been deleted.

func (Deleted) Resource

func (Deleted) Resource() store.Resource

Resource implements Resourcer.Resource on Deleted.

type Disconnected

type Disconnected ConnectionNotif

Disconnected is a Resourcer which can notify that a user has disconnected.

func (Disconnected) Resource

func (Disconnected) Resource() store.Resource

Resource implements Resourcer.Resource on Disconnected.

type Entry

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

Entry is a Scribe log entry. Its key is an RFC3339 timestamp and its value is the JSON representation of the message.

type Message

type Message struct {
	Sender    string    `json:"sender"`
	Content   string    `json:"content"`
	Timestamp time.Time `json:"timestamp"`
}

Message is a container for a convo message.

func GetMessageRange

func GetMessageRange(
	convoID string,
	from, to time.Time,
	max int,
	tx *bolt.Tx,
) ([]Message, error)

GetMessageRange gets a slice of up to max Messages for the given time range in the given Convo.

func GetMessages

func GetMessages(convoID string, tx *bolt.Tx) ([]Message, error)

GetMessages gets a slice of up to 50 Messages for the last week in the given Convo.

type Removed

type Removed string

Removed is a Resourcer which can notify that the user has been removed from the Convo without showing the user the Convo.

func (Removed) Resource

func (Removed) Resource() store.Resource

Resource implements Resourcer.Resource on Removed.

type Scribe

type Scribe string

Scribe is a BUS consumer which does nothing but log received messages to the Messages bucket under its ID (which is the same ID as the stream it belongs to.)

func (Scribe) CheckExists

func (s Scribe) CheckExists(tx *bolt.Tx) error

CheckExists is a bolt View function which returns nil if the given Scribe is already running. The Scribe should have the same ID as the Stream it is logging. If the Scribe does not exist, this returns errNotExists.

func (Scribe) Checkin

func (s Scribe) Checkin(tx *bolt.Tx) (uint64, bool, error)

Checkin is a bolt Update function which a sequence ID, and true, if the caller is the first caller for the given Scribe. If this returns true, the caller should also use Scribe.Spawn to start a new Scribe.

func (Scribe) Checkout

func (s Scribe) Checkout(id uint64, tx *bolt.Tx) (bool, error)

Checkout is a bolt Update function which takes a sequence ID, and returns true if it is the last to check out. If it is the last to check out, the caller should also call Scribe.Hangup.

func (Scribe) DeleteCheckins

func (s Scribe) DeleteCheckins(tx *bolt.Tx) error

DeleteCheckins deletes the Checkin / Checkout bucket for the Scribe. Only use this once all convo members have disconnected.

func (Scribe) Hangup

func (s Scribe) Hangup(db *bolt.DB) error

Hangup closes the Scribe.

func (Scribe) Spawn

func (s Scribe) Spawn(tx *bolt.Tx) error

Spawn is a Bolt Update function which creates a new Scribe Bus, listening to the given stream in a goroutine. It also creates a Responder, so the Scribe can be hung up. To hang it up and clean it from the database, use Scribe.Hangup.

TODO: Tighten this up using DB funcs in message.go.

type Sender

type Sender struct {
	util.Timer
	Name string
}

Sender is a User who reads stream.Messages from a websocket Conn and binds their contents into a new convo.Message with the attached user.

func (Sender) Read

func (s Sender) Read(conn *ws.Conn) ([]byte, bool, error)

Read is a SocketReader for passing to ws.Bind which wraps a received stream.Message contents with the Sender's userID in a convo.Message, and marshals the convo.Message into bytes.

A false bool return value indicates a normal or non-fatal error, such as a syntax error, so that the caller will know to notify the sender and continue to the next Read.

Jump to

Keyboard shortcuts

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