types

package
v0.0.0-...-fcbdc9d Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeInfo        = "info"
	EventTypeChat        = "chat"
	EventTypeCommand     = "command"
	EventTypeUser        = "user"
	EventTypeTranslation = "translation"
	EventTypeInternal    = "_internal"
)
View Source
const (
	WireMessageTypeInfo         = "info"
	WireMessageTypeChat         = "chat"
	WireMessageTypeLogin        = "login"
	WireMessageTypeLogout       = "logout"
	WireMessageTypeUser         = "user"
	WireMessageTypeTranslation  = "translation"
	WireMessageTypeCommand      = "command"
	WireMessageTypeGeneric      = "generic"
	WireMessageTypeChats        = "chats"
	WireMessageTypeTranslations = "translations"
	WireMessageTypeUsers        = "users"
	WireMessageTypeCommands     = "commands"
	WireMessageTypeGenerics     = "generics"
)
View Source
const (
	TagValueTypeString      = 0
	TagValueTypeInt         = 1
	TagValueTypeFloat       = 2
	TagValueTypeStringSlice = 3
	TagValueTypeIntSlice    = 4
	TagValueTypeFloatSlice  = 5
)

Make sure those constants are the same as defined in the proto enum!

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	Nick      string    `json:"nick" mapstructure:"-"`                   // sender nick, outgoing
	Timestamp time.Time `json:"timestamp" mapstructure:"-"`              // sent time, outgoing
	Message   string    `json:"message" mapstructure:"message"`          // actual message, incoming + outgoing
	Language  string    `json:"language" hash:"ignore" mapstructure:"-"` // language of the message (for future use), outgoing
	Filter    string    `json:"filter" mapstructure:"filter"`            // filter expression incoming
}

ChatMessage is a basic chat message, contains the sender nick

type Event

type Event struct {
	Id       string `json:"id" hash:"ignore" gorm:"primaryKey"`
	RoomId   string `json:"-"`
	Room     *Room  `json:"room"`
	*Source  `json:"source" gorm:"embeddedPrefix:source_"`
	Created  time.Time     `json:"created" gorm:"autoCreateTime;index"`
	Language string        `json:"language"`
	Name     string        `json:"name"`
	Tags     JSONStringMap `json:"tags"`
	History  bool          `json:"history" gorm:"-"` // set to true is this event is sent from history

	// the following fields are not part of the filter.Env!
	Sent         time.Time `json:"sent" hash:"ignore"`
	TargetFilter string    `json:"target_filter"`

	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}

func NewEvent

func NewEvent(room *Room, source *Source, targetFilter string, language string, name string, tags map[string]string) *Event

NewEvent creates a new event with the given parameters.

The resulting *Event has no `nil` values, the Created timestamp is set to now.

type JSONStringMap

type JSONStringMap map[string]string

JSONStringMap defined JSON data type, need to implements driver.Valuer, sql.Scanner interface

func (JSONStringMap) GormDBDataType

func (JSONStringMap) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type

func (JSONStringMap) GormDataType

func (m JSONStringMap) GormDataType() string

GormDataType gorm common data type

func (JSONStringMap) MarshalJSON

func (m JSONStringMap) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte

func (*JSONStringMap) Scan

func (m *JSONStringMap) Scan(val interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (*JSONStringMap) UnmarshalJSON

func (m *JSONStringMap) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte

func (JSONStringMap) Value

func (m JSONStringMap) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type LoginMessage

type LoginMessage struct {
	IdToken  string `json:"id_token" mapstructure:"id_token"`
	Provider string `json:"provider" mapstructure:"provider"`
	Language string `json:"language" mapstructure:"language"`
}

LoginMessage is sent when a client logs in and contains the id token, the provider and the user's language setting

type Room

type Room struct {
	Id        string         `json:"id" gorm:"primaryKey"`
	OwnerId   string         `json:"-"`
	Owner     *User          `json:"owner"`
	Tags      JSONStringMap  `json:"tags"` // tags
	CreatedAt time.Time      `json:"-"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
	// contains filtered or unexported fields
}

this is basically identified with one hub, it is just a logical separation

type Source

type Source struct {
	UserId     string `json:"-"`
	User       *User  `json:"user"`
	PluginName string `json:"plugin_name"`
}

type TagUpdate

type TagUpdate struct {
	Name       string `json:"name"`       // tag name
	Type       int    `json:"type"`       // type - TagValueType* const
	Index      int    `json:"index"`      // used for slice types
	Expression string `json:"expression"` // expr expression to apply to the Tags, the tag "Name" is set to the resulting value
}

a slice of TagUpdate objects is used for atomically updating Tags values (users/rooms/...)

type User

type User struct {
	Id         string         `json:"id" gorm:"primaryKey"`      // unique id
	Nick       string         `json:"nick" gorm:"index"`         // should also be unique
	Language   string         `json:"language"`                  // alpha-2 iso
	Tags       JSONStringMap  `json:"tags"`                      // tags
	LastOnline time.Time      `json:"last_online" hash:"ignore"` // last seen online
	CreatedAt  time.Time      `json:"-"`
	UpdatedAt  time.Time      `json:"-"`
	DeletedAt  gorm.DeletedAt `json:"-" gorm:"index"`
}

type WebsocketMessage

type WebsocketMessage struct {
	Event string          `json:"event"`
	Data  json.RawMessage `json:"data"`
}

JSON-serialized WebsocketMessage is what is actually sent via the Websocket connection

type WireEvent

type WireEvent struct {
	*Event
	Name         omit `json:"name,omitempty"` // not required, wired as the "event"
	TargetFilter omit `json:"target_filter,omitempty"`
}

func (WireEvent) MarshalJSON

func (e WireEvent) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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