Documentation ¶
Index ¶
- Constants
- Variables
- func AddPersonWithKeys(pStmt, pkStmt *sql.Stmt, email string, pkList []*PUBLIC_KEY) error
- func CleanupMessages(idStmt, msgStmt, recipientStmt *sql.Stmt) []error
- func CleanupSessions(stmt *sql.Stmt) error
- func ExpiredMessages(stmt *sql.Stmt) ([]string, error)
- func InitializeWords(wordsFile string) error
- func WithDatabase(dbCoords DBConnection, fn func(map[string]*sql.Stmt))
- type DBConnection
- type MESSAGE
- func (m *MESSAGE) Add(stmt *sql.Stmt, duration time.Duration) (string, error)
- func (m *MESSAGE) AddRecipients(stmt *sql.Stmt, recipients []*PERSON) []error
- func (m *MESSAGE) Delete(stmt *sql.Stmt) error
- func (m *MESSAGE) DeleteRecipients(stmt *sql.Stmt, recipients []*PERSON) []error
- func (m *MESSAGE) GetDigest(personStmt, recipientStmt *sql.Stmt, personId string) (*MESSAGE_DIGEST, error)
- func (m *MESSAGE) GetPreview() string
- func (m *MESSAGE) ProcessRecipients(stmt *sql.Stmt, recipients []*PERSON) []error
- type MESSAGE_DIGEST
- type PERSON
- func (p *PERSON) Add(stmt *sql.Stmt) (string, error)
- func (p *PERSON) Delete(stmt *sql.Stmt) error
- func (p *PERSON) LookupAuthoredMessages(stmt *sql.Stmt, limit, offset int64) ([]*MESSAGE, error)
- func (p *PERSON) LookupInvolvedMessages(stmt *sql.Stmt, limit, offset int64) ([]*MESSAGE, error)
- func (p *PERSON) LookupLatestMessages(stmt *sql.Stmt, limit, offset int64) ([]*MESSAGE, error)
- func (p *PERSON) LookupMessages(stmt *sql.Stmt, usePersonId bool, limit, offset int64) ([]*MESSAGE, error)
- func (p *PERSON) LookupPublicKeys(stmt *sql.Stmt) ([]*PUBLIC_KEY, error)
- func (p *PERSON) LookupRecipientMessages(stmt *sql.Stmt, limit, offset int64) ([]*MESSAGE, error)
- func (p *PERSON) LookupSessions(stmt *sql.Stmt) ([]*SESSION, error)
- func (p *PERSON) Update(stmt *sql.Stmt) error
- type PUBLIC_KEY
- type SESSION
Constants ¶
const ( // add + delete MESSAGE_INSERT = "insert into message (person_id, message, date_expires) values ($1, $2, $3 at time zone 'UTC') returning id" MESSAGE_DELETE = "delete from message where id = $1" MESSAGE_CLEANUP = "select id from message where date_expires <= (now() at time zone 'UTC')" RECIPIENT_INSERT = "insert into message_recipient (message_id, person_id) values ($1, $2)" RECIPIENT_DELETE = "delete from message_recipient where message_id = $1 and person_id = $2" RECIPIENT_CLEANUP = "delete from message_recipient where message_id = $1" // lookups MESSAGES_BY_AUTHOR = "select id, person_id, message, date_posted, date_expires from message where person_id = $1" MESSAGES_BY_RECIPIENT = "" /* 152-byte string literal not displayed */ RECIPIENTS_BY_MESSAGE = "select person_id from message_recipient where message_id = $1" LATEST_MESSAGES = "select id, person_id, message, date_posted, date_expires from message order by date_posted desc limit $1 offset $2" LATEST_MESSAGES_INVOLVING_PERSON = `` /* 224-byte string literal not displayed */ MESSAGE_BY_ID = "select id, person_id, message, date_posted, date_expires from message where id = $1 limit $2 offset $3" )
const ( // person a/u/d PERSON_INSERT = "insert into person (email) values ($1) returning id" PERSON_UPDATE = "update person set email = $1, verified = $2, date_verified = (now() at time zone 'UTC'), enabled = $3 where id = $4" PERSON_DELETE = "delete from person where id = $1" // person lookup PERSON_LOOKUP_BY_ID = "select id, email, date_added, verified, date_verified, enabled from person where id = $1" PERSON_LOOKUP_BY_EMAIL = "select id, email, date_added, verified, date_verified, enabled from person where email = $1" )
const ( // public key a/u/d PK_INSERT = "insert into public_key (person_id, key, nickname, source) values ($1, $2, $3, $4) returning id" PK_UPDATE = "update public_key set key = $1, nickname = $2, source = $3 where id = $4" PK_DELETE = "delete from public_key where id = $1" // public key lookup PK_LOOKUP = "select id, key, date_added, nickname, source from public_key where person_id = $1" )
const ( // session a/u/d SESSION_INSERT = "insert into session (session_code, person_id, date_expires) values ($1, $2, $3 at time zone 'UTC') returning id" SESSION_UPDATE = "update session set verified = $1, date_verified = (now() at time zone 'UTC') where id = $2" SESSION_CLEANUP = "delete from session where date_expires <= (now() at time zone 'UTC')" // session lookup SESSION_LOOKUP_BY_CODE = "select id, person_id, session_code, date_created, verified, date_verified, date_expires from session where session_code = $1" SESSION_LOOKUP_BY_ID = "select id, person_id, session_code, date_created, verified, date_verified, date_expires from session where id = $1" SESSION_LOOKUP_BY_PERSON = "select id, person_id, session_code, date_created, verified, date_verified, date_expires from session where person_id = $1" )
Variables ¶
var WordTokens []string
Functions ¶
func AddPersonWithKeys ¶
func AddPersonWithKeys(pStmt, pkStmt *sql.Stmt, email string, pkList []*PUBLIC_KEY) error
create a new Person in the db, and associate these public keys
func CleanupMessages ¶
Identify all expired messages, and remove them and their recipient list
func CleanupSessions ¶
func ExpiredMessages ¶
Return a list of message ids that are now expired
func InitializeWords ¶
func WithDatabase ¶
func WithDatabase(dbCoords DBConnection, fn func(map[string]*sql.Stmt))
Connect to the database with the given coordinates, and invoke the function, which gets passed a map of all the prepared statements
Types ¶
type MESSAGE ¶
type MESSAGE struct { Id string `json:"id"` PersonId string `json:"person_id"` Message string `json:"message"` DatePosted time.Time `json:"date_posted"` DateExpires time.Time `json:"date_expires"` }
func RetrieveMessages ¶
Return a list of messages for the given query limit/offset criteria
func (*MESSAGE) AddRecipients ¶
func (*MESSAGE) DeleteRecipients ¶
func (*MESSAGE) GetDigest ¶
func (m *MESSAGE) GetDigest(personStmt, recipientStmt *sql.Stmt, personId string) (*MESSAGE_DIGEST, error)
Retrieve the corresponding digest (which includes all the involved Person objects) for this Message
func (*MESSAGE) GetPreview ¶
Fetch the first unique line of the armored message as a preview
type MESSAGE_DIGEST ¶
type MESSAGE_DIGEST struct { Message *MESSAGE Preview string Sender *PERSON Recipients []*PERSON InvolvesRequestor bool }
func GetMessageDigests ¶
func GetMessageDigests(personStmt, recipientStmt *sql.Stmt, messages []*MESSAGE, personId string) ([]*MESSAGE_DIGEST, []error)
Return the corresponding digests for this list of messages
type PERSON ¶
type PERSON struct { Id string `json:"id"` Email string `json:"email"` DateAdded time.Time `json:"date_joined"` Verified bool `json:"verified"` DateVerified time.Time `json:"date_verified,omitempty"` Enabled bool `json:"enabled"` }
func (*PERSON) LookupAuthoredMessages ¶
Return a list of messages originated by this person
func (*PERSON) LookupInvolvedMessages ¶
Return a list of messages in which this person was involved, either as an origniator or a recipient
func (*PERSON) LookupLatestMessages ¶
Return a list of all messages, regardless of involvement by this person
func (*PERSON) LookupMessages ¶
func (*PERSON) LookupPublicKeys ¶
func (p *PERSON) LookupPublicKeys(stmt *sql.Stmt) ([]*PUBLIC_KEY, error)
func (*PERSON) LookupRecipientMessages ¶
Return a list of messages in which this person was a recipient
type PUBLIC_KEY ¶
type SESSION ¶
type SESSION struct { Id string `json:"id"` PersonId string `json:"person_id"` Code string `json:"session_code"` DateCreated time.Time `json:"date_created"` Verified bool `json:"verified"` DateVerified time.Time `json:"date_verified"` DateExpires time.Time `json:"date_expires"` }