facechat

package
v0.0.0-...-273060c Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const MaxMessageLen = 2048

MaxMessageLen is the maximum number of bytes per message.

View Source
const MaxMessagesQuery = 100

MaxMessagesQuery is the maximum number of messages per GET query.

View Source
const MaxRoomNameLen = 64
View Source
const MinAccounts = 1
View Source
const RoomsPerUser = 3

RoomsPerUser is the maximum number of rooms a user can make. This may change in the future.

View Source
const SessionTimeout = 7 * 24 * time.Hour

Variables

View Source
var (
	ErrNotInRoom       = httperr.New(401, "you're not in this room")
	ErrRoomNotFound    = httperr.New(404, "room not found")
	ErrIllegalRoomName = httperr.New(400, "room name contains invalid characters")
)
View Source
var ErrMessageLimitInvalid = httperr.New(400, "message 0 < limit < 100 invalid")
View Source
var ErrNoAccountsLinked = httperr.New(400, "no accounts linked")
View Source
var ErrNotMutual = httperr.New(401, "not mutual friends")
View Source
var ErrUnknownSession = httperr.New(401, "unknown session")
View Source
var ErrUserNotFound = httperr.New(404, "user not found")

Functions

func ValidateRoomName

func ValidateRoomName(name string) error

ValidateRoomName returns nil if the room name is valid.

Types

type Account

type Account struct {
	Service string          `json:"service"       db:"service"`
	Name    string          `json:"name"          db:"name"`
	URL     string          `json:"url"           db:"url"`
	Data    json.RawMessage `json:"data"          db:"data"`
	UserID  ID              `json:"userID,string" db:"user_id"`
}

type ID

type ID uint64

func GenerateID

func GenerateID() ID

func (ID) String

func (id ID) String() string

type Message

type Message struct {
	ID       ID          `json:"id,string"        db:"id"`
	Type     MessageType `json:"type"             db:"type"`
	RoomID   ID          `json:"room_id,string"   db:"room_id"`
	AuthorID ID          `json:"author_id,string" db:"author_id"`
	Markdown string      `json:"markdown"         db:"markdown"`
}

type MessageType

type MessageType int8
const (
	NormalMessage MessageType = iota
	JoinMessage
	LeaveMessage
	DeletedMessage // soft delete
)

type PrivateRoom

type PrivateRoom struct {
	RoomID     ID `json:"room_id"    db:"room_id"`
	Recipient1 ID `json:"recipient1" db:"recipient1"`
	Recipient2 ID `json:"recipient2" db:"recipient2"`
}

type Relationship

type Relationship struct {
	TargetID ID               `json:"target_id,string" db:"target_id"`
	Type     RelationshipType `json:"type"             db:"type"`
}

type RelationshipType

type RelationshipType uint8
const (
	Stranger RelationshipType = iota
	Blocked
	Friend
)

type Room

type Room struct {
	ID    ID          `json:"id,string" db:"id"`
	Name  string      `json:"name"      db:"name"`
	Topic string      `json:"topic"     db:"topic"`
	Level SecretLevel `json:"level"     db:"level"`
}

type SecretLevel

type SecretLevel int8
const (
	// Anonymous means that no username, avatar nor any personal information is
	// exposed. This is the equivalent of anonymous image boards.
	Anonymous SecretLevel = iota
	// HalfOpen exposes the username and avatar.
	HalfOpen
	// FullyOpen exposes all information, including social media accounts.
	FullyOpen
	// Private is reserved for private rooms. It is the same as FullyOpen.
	Private
)

type Session

type Session struct {
	UserID ID        `json:"-" db:"user_id"`
	Token  string    `json:"-" db:"token"`
	Expiry time.Time `json:"-" db:"expiry"`
}

type User

type User struct {
	ID    ID     `json:"id,string" db:"id"`
	Name  string `json:"name"      db:"name"`
	Email string `json:"email"     db:"email"`
}

Jump to

Keyboard shortcuts

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