storage

package
v0.0.0-...-1cbd5f8 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2015 License: Apache-2.0 Imports: 15 Imported by: 8

Documentation

Overview

The storage package manages setting up the database ond knows how to fetch and update all relevant data.

Index

Constants

This section is empty.

Variables

View Source
var (
	PresenceStates map[string]PresenceState = map[string]PresenceState{
		"free for chat": P_FREEFORCHAT,
		"online":        P_ONLINE,
		"unavailable":   P_UNAVAILABLE,
		"hidden":        P_HIDDEN,
		"offline":       P_OFFLINE,
	}
)

Functions

func CreateEvent

func CreateEvent(tx TX, event_id m.EventID, user_id m.UserID, room_id m.RoomID, event_type string, content map[string]interface{}) error

func CreateStateEvent

func CreateStateEvent(tx TX, event_id m.EventID, user_id m.UserID, room_id m.RoomID, event_type, state_key string, content map[string]interface{}) error

func GetPowerLevel

func GetPowerLevel(db DBI, room_id m.RoomID, state_key string) (int64, error)

func LookupRoomAlias

func LookupRoomAlias(db DBI, room_alias m.RoomAlias) (m.RoomID, []string, error)

func NewEvent

func NewEvent(tx TX, user_id m.UserID, room_id m.RoomID, event_type string, content map[string]interface{}) (m.EventID, error)

func NewStateEvent

func NewStateEvent(tx TX, user_id m.UserID, room_id m.RoomID, event_type, state_key string, content map[string]interface{}) (m.EventID, error)

func Now

func Now() int64

func Setup

func Setup() error

Types

type AccessToken

type AccessToken struct {
	ID       DBID
	User     *User
	Token    Token
	LastUsed Timestamp
	Created  Timestamp
}

func NewAccessToken

func NewAccessToken(db DBI, u *User) (*AccessToken, error)

func (*AccessToken) UpdateAccessToken

func (t *AccessToken) UpdateAccessToken(db DBI) error

type DB

type DB interface {
	DBI
	Begin() (*sql.Tx, error)
}

func GetDatabase

func GetDatabase() DB

type DBI

type DBI interface {
	Exec(string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
}

The DBI is something that can do something on a database, normally either a `*sql.DB` or a `*sql.Tx`.

type DBID

type DBID int64

type Password

type Password string

func (Password) MakeHash

func (p Password) MakeHash(salt string) PasswordHash

type PasswordHash

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

func (PasswordHash) Equal

func (p PasswordHash) Equal(password string) bool

func (PasswordHash) Hash

func (p PasswordHash) Hash() string

func (PasswordHash) Salt

func (p PasswordHash) Salt() string

type Presence

type Presence struct {
	User           *User
	Presence       PresenceState
	PresenceString string
	Status         string
	MTime          int64
}

type PresenceState

type PresenceState int
const (
	P_FREEFORCHAT PresenceState = 20
	P_ONLINE      PresenceState = 10
	P_UNAVAILABLE PresenceState = 5
	P_HIDDEN      PresenceState = 1
	P_OFFLINE     PresenceState = 0
)

func (PresenceState) String

func (p PresenceState) String() string

type Profile

type Profile struct {
	User        *User
	DisplayName string
	AvatarURL   string
}

func NewProfile

func NewProfile(db DBI, u *User) (*Profile, error)

func (*Profile) UpdateAvatarURL

func (p *Profile) UpdateAvatarURL(db DBI, newurl string) error

func (*Profile) UpdateDisplayName

func (p *Profile) UpdateDisplayName(db DBI, newname string) error

type Room

type Room struct {
	ID            m.RoomID `json:"-"`
	Aliases       []string `json:"aliases"`
	Name          string   `json:"name"`
	JoinedMembers int      `json:"num_joined_members"`
	RoomId        string   `json:"room_id"`
	Topic         string   `json:"topic"`
}

func CreateRoom

func CreateRoom(tx TX, creator m.UserID, is_public bool) (*Room, error)

func GetPublicRooms

func GetPublicRooms(db DBI) []Room

func GetRoom

func GetRoom(db DBI, room_id m.RoomID) (*Room, error)

func (*Room) CheckedUpdateMember

func (r *Room) CheckedUpdateMember(tx TX, sender, target m.UserID, new_membership m.RoomMembership) (err error)

func (*Room) GetInviteLevel

func (r *Room) GetInviteLevel(db DBI) (invite int64, err error)

func (*Room) GetJoinRule

func (r *Room) GetJoinRule(db DBI) (m.RoomJoinRule, error)

func (*Room) GetOpsLevels

func (r *Room) GetOpsLevels(db DBI) (ban int64, kick int64, redact int64, err error)

func (*Room) GetUserMembership

func (r *Room) GetUserMembership(db DBI, user_id m.UserID) (m.RoomMembership, error)

func (*Room) GetUserPowerLevel

func (r *Room) GetUserPowerLevel(db DBI, user_id m.UserID) (int64, error)

func (*Room) InviteMember

func (r *Room) InviteMember(tx TX, sender m.UserID, target m.UserID) error

func (*Room) UpdateAddStateLevel

func (r *Room) UpdateAddStateLevel(tx TX, sender m.UserID, new_level int64) (err error)

func (*Room) UpdateAliases

func (r *Room) UpdateAliases(tx TX, sender m.UserID, new_aliases []m.RoomAlias) (err error)

func (*Room) UpdateJoinRule

func (r *Room) UpdateJoinRule(tx TX, sender m.UserID, new_join_rule m.RoomJoinRule) (err error)

func (*Room) UpdateMember

func (r *Room) UpdateMember(tx TX, sender m.UserID, target m.UserID, new_membership m.RoomMembership) (err error)

func (*Room) UpdateName

func (r *Room) UpdateName(tx TX, sender m.UserID, new_name string) (err error)

func (*Room) UpdateOpsLevel

func (r *Room) UpdateOpsLevel(tx TX, sender m.UserID, new_levels map[string]int64) (err error)

func (*Room) UpdatePowerLevels

func (r *Room) UpdatePowerLevels(tx TX, sender m.UserID, new_levels map[m.UserID]int64, default_level *int64) (err error)

func (*Room) UpdateSendEventLevel

func (r *Room) UpdateSendEventLevel(tx TX, sender m.UserID, new_level int64) (err error)

func (*Room) UpdateTopic

func (r *Room) UpdateTopic(tx TX, sender m.UserID, new_topic string) (err error)

type TX

type TX interface {
	DBI
	Commit() error
	Rollback() error
}

type Timestamp

type Timestamp int64

type Token

type Token string

type User

type User struct {
	ID       DBID
	UserID   m.UserID
	Password PasswordHash
	Created  Timestamp
	Profile  *Profile
}

func CreateUser

func CreateUser(db DBI, user_id m.UserID) (*User, error)

func GetUser

func GetUser(db DBI, uid m.UserID) (*User, error)

func GetUserByToken

func GetUserByToken(db DBI, token Token) (*User, error)

func (*User) GetAccessToken

func (u *User) GetAccessToken(db DBI) (*AccessToken, error)

func (*User) GetInitialPresence

func (u *User) GetInitialPresence(db DBI) ([]o.InitialSyncEvent, error)

func (*User) GetPresence

func (u *User) GetPresence(db DBI) (*Presence, error)

func (*User) GetProfile

func (u *User) GetProfile(db DBI) (*Profile, error)

func (*User) GetRoomMemberships

func (u *User) GetRoomMemberships(db DBI, limit uint64) ([]o.InitialSyncRoomData, error)

Fetch the users joined rooms and return it in a list for initial sync. limit is used to limit the number of messages that is returned for each room.

func (*User) SetPassword

func (u *User) SetPassword(db DBI, passwordstring string) error

func (*User) UpdatePassword

func (u *User) UpdatePassword(db DBI, hash PasswordHash) error

func (*User) UpdatePresence

func (u *User) UpdatePresence(db DBI, newpresence PresenceState, message string) error

Jump to

Keyboard shortcuts

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