models

package
v0.0.0-...-e00079b Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2015 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NonceBytes = 32
)

Variables

View Source
var (
	// Db is the global database context
	Db = NewDbContext(os.Getenv("DATABASE_URL"))
)

Functions

func AlertTeamOfMentions

func AlertTeamOfMentions(roomId, body string, mentions []string) error

func CreateMessage

func CreateMessage(fields *Message) error

func DeleteRoom

func DeleteRoom(slug, teamId string) error

func DeleteRoomMembership

func DeleteRoomMembership(roomId, userId string) error

func FindRoomMemberships

func FindRoomMemberships(userId string) ([]string, error)

func NewDbContext

func NewDbContext(url string) *gorp.DbMap

NewDbContext initialises a new database context

func NonceValid

func NonceValid(nonce string) bool

func ParseMessage

func ParseMessage(message *Message) string

ParseMessage parses the outgoing message by catching user and room mentions, URLs, and then passing the body through Blackfriday for additional parsing and finally Bluemonday for sanitization.

func PostToTeamWebhook

func PostToTeamWebhook(roomId string, message *Message) error

func ShaString

func ShaString(raw []byte) string

func Sign

func Sign(secret, payload []byte) string

func Subscribers

func Subscribers(roomId string) (*[]string, error)

func SubscribersWithoutUser

func SubscribersWithoutUser(roomId, userId string) (*[]string, error)

func TouchUser

func TouchUser(userId string)

func UnreadRooms

func UnreadRooms(userId string) (interface{}, error)

Types

type Message

type Message struct {
	Id        string    `db:"id" json:"id"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
	RoomId    string    `db:"room_id" json:"room_id"`
	UserId    string    `db:"user_id" json:"user_id"`
	Body      string    `db:"body" json:"body"`
}

func (*Message) PreInsert

func (o *Message) PreInsert(s gorp.SqlExecutor) error

func (*Message) PreUpdate

func (o *Message) PreUpdate(s gorp.SqlExecutor) error

type MessageWithUser

type MessageWithUser struct {
	Id           string    `db:"id" json:"id"`
	CreatedAt    time.Time `db:"created_at" json:"created_at"`
	Body         string    `db:"body" json:"body"`
	HTMLBody     string    `json:"html_body"`
	Username     string    `db:"username" json:"username"`
	AvatarUrl    string    `db:"avatar_url" json:"avatar_url"`
	LastOnlineAt time.Time `db:"last_online_at" json:"last_online_at"`
	ProfileUrl   string    `db:"profile_url" json:"profile_url"`
}

func FindMessages

func FindMessages(roomId string) ([]MessageWithUser, error)

func FindMessagesBeforeTimestamp

func FindMessagesBeforeTimestamp(roomId string, timestamp time.Time) ([]MessageWithUser, error)

func NewMessageWithUser

func NewMessageWithUser(message *Message, user *User) *MessageWithUser

NewMessageWithUser parses the message body and joins the user to it

type Nonce

type Nonce struct {
	Id        string    `db:"id" json:"-"`
	ExpiresAt time.Time `db:"expires_at" json:"expires_at"`
	Nonce     string    `db:"nonce" json:"nonce"`
}

func CreateNonce

func CreateNonce() (*Nonce, error)

type Room

type Room struct {
	Id        string     `db:"id" json:"id"`
	CreatedAt time.Time  `db:"created_at" json:"created_at"`
	DeletedAt *time.Time `db:"deleted_at" json:"deleted_at"`
	UpdatedAt time.Time  `db:"updated_at" json:"updated_at"`
	TeamId    string     `db:"team_id" json:"team_id"`
	Slug      string     `db:"slug" json:"slug"`
	Topic     string     `db:"topic" json:"topic"`
}

func FindOrCreateRoom

func FindOrCreateRoom(fields *Room) (*Room, error)

func FindRoom

func FindRoom(slug, teamId string) (*Room, error)

func FindRoomById

func FindRoomById(id string) *Room

func FindRooms

func FindRooms(teamId string) ([]Room, error)

func UpdateRoom

func UpdateRoom(slug, teamId string, fields *Room) (*Room, error)

func (*Room) PreInsert

func (o *Room) PreInsert(s gorp.SqlExecutor) error

func (*Room) PreUpdate

func (o *Room) PreUpdate(s gorp.SqlExecutor) error

type RoomMembership

type RoomMembership struct {
	Id        string     `db:"id" json:"id"`
	CreatedAt time.Time  `db:"created_at" json:"created_at"`
	DeletedAt *time.Time `db:"deleted_at" json:"deleted_at"`
	UpdatedAt time.Time  `db:"updated_at" json:"updated_at"`
	RoomId    string     `db:"room_id" json:"room_id"`
	UserId    string     `db:"user_id" json:"user_id"`
}

func FindOrCreateRoomMembership

func FindOrCreateRoomMembership(fields *RoomMembership) (*RoomMembership, error)

func (*RoomMembership) PreInsert

func (o *RoomMembership) PreInsert(s gorp.SqlExecutor) error

func (*RoomMembership) PreUpdate

func (o *RoomMembership) PreUpdate(s gorp.SqlExecutor) error

type SSORequest

type SSORequest struct {
	Payload    string
	Signature  string
	Nonce      string
	TeamSlug   string
	ExternalId string
	AvatarUrl  string
	Username   string
	Email      string
	ProfileUrl string
	RealName   string
}

func (*SSORequest) IsValid

func (r *SSORequest) IsValid(secret string) bool

type Team

type Team struct {
	Id                string    `db:"id" json:"id"`
	CreatedAt         time.Time `db:"created_at" json:"created_at"`
	UpdatedAt         time.Time `db:"updated_at" json:"updated_at"`
	Email             string    `db:"email" json:"email"`
	EncryptedPassword string    `db:"encrypted_password" json:"encrypted_password"`
	SSOSecret         string    `db:"sso_secret" json:"-"`
	SSOUrl            string    `db:"sso_url" json:"sso_url"`
	Slug              string    `db:"slug" json:"slug"`
	WebhookURL        *string   `db:"webhook_url" json:"webhook_url"`
}

func FindOrCreateTeam

func FindOrCreateTeam(fields *Team) (*Team, error)

func FindTeamById

func FindTeamById(id string) *Team

func FindTeamBySecret

func FindTeamBySecret(slug, secret string) *Team

func FindTeamBySlug

func FindTeamBySlug(slug string) *Team

func UpdateTeam

func UpdateTeam(slug string, fields *Team) (*Team, error)

func (*Team) PreInsert

func (o *Team) PreInsert(s gorp.SqlExecutor) error

func (*Team) PreUpdate

func (o *Team) PreUpdate(s gorp.SqlExecutor) error

type UnreadAlert

type UnreadAlert struct {
	Key        string    `json:"key"`
	Recipients *[]string `json:"recipients"`
}

type User

type User struct {
	Id           string    `db:"id" json:"id"`
	CreatedAt    time.Time `db:"created_at" json:"created_at"`
	UpdatedAt    time.Time `db:"updated_at" json:"updated_at"`
	LastOnlineAt time.Time `db:"last_online_at" json:"last_online_at"`
	TeamId       string    `db:"team_id" json:"team_id"`

	AvatarUrl  string `db:"avatar_url" json:"avatar_url"`
	Email      string `db:"email" json:"email"`
	ExternalId string `db:"external_id" json:"external_id"`
	ProfileUrl string `db:"profile_url" json:"profile_url"`
	RealName   string `db:"real_name" json:"real_name"`
	Username   string `db:"username" json:"username"`
}

func FindOrCreateUserByExternalId

func FindOrCreateUserByExternalId(fields *User) (*User, error)

func FindRecentlyOnlineUsers

func FindRecentlyOnlineUsers(teamId string) ([]User, error)

func FindUser

func FindUser(id string) (*User, error)

func FindUserByExternalIDAndTeam

func FindUserByExternalIDAndTeam(externalID, teamID string) (*User, error)

func FindUserByUsernameAndTeam

func FindUserByUsernameAndTeam(username, teamId string) (*User, error)

func FindUsers

func FindUsers(teamId string) ([]User, error)

func SearchUsersByUsernameLike

func SearchUsersByUsernameLike(partialUsername, teamId string) ([]User, error)

func (*User) PreInsert

func (o *User) PreInsert(s gorp.SqlExecutor) error

func (*User) PreUpdate

func (o *User) PreUpdate(s gorp.SqlExecutor) error

Jump to

Keyboard shortcuts

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