✨ Basic realtime text command
This commit is contained in:
@ -1,12 +1,23 @@
|
||||
package models
|
||||
|
||||
type ChannelType = uint8
|
||||
|
||||
const (
|
||||
ChannelTypeDirect = ChannelType(iota)
|
||||
ChannelTypeRealm
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
BaseModel
|
||||
|
||||
Alias string `json:"alias" gorm:"uniqueIndex"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Members []ChannelMember `json:"members"`
|
||||
Messages []Message `json:"messages"`
|
||||
Type ChannelType `json:"type"`
|
||||
AccountID uint `json:"account_id"`
|
||||
RealmID uint `json:"realm_id"`
|
||||
}
|
||||
|
||||
type ChannelMember struct {
|
||||
@ -16,4 +27,6 @@ type ChannelMember struct {
|
||||
AccountID uint `json:"account_id"`
|
||||
Channel Channel `json:"channel"`
|
||||
Account Account `json:"account"`
|
||||
|
||||
Messages []Message `json:"messages" gorm:"foreignKey:SenderID"`
|
||||
}
|
||||
|
21
pkg/models/messages.go
Normal file
21
pkg/models/messages.go
Normal file
@ -0,0 +1,21 @@
|
||||
package models
|
||||
|
||||
import "gorm.io/datatypes"
|
||||
|
||||
type MessageType = uint8
|
||||
|
||||
const (
|
||||
MessageTypeText = MessageType(iota)
|
||||
MessageTypeAudio
|
||||
MessageTypeFile
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
BaseModel
|
||||
|
||||
Content string `json:"content"`
|
||||
Metadata datatypes.JSONMap `json:"metadata"`
|
||||
Type MessageType `json:"type"`
|
||||
ChannelID uint `json:"channel_id"`
|
||||
SenderID uint `json:"sender_id"`
|
||||
}
|
21
pkg/models/unified.go
Normal file
21
pkg/models/unified.go
Normal file
@ -0,0 +1,21 @@
|
||||
package models
|
||||
|
||||
import jsoniter "github.com/json-iterator/go"
|
||||
|
||||
type UnifiedCommand struct {
|
||||
Action string `json:"w"`
|
||||
Message string `json:"m"`
|
||||
Payload any `json:"p"`
|
||||
}
|
||||
|
||||
func UnifiedCommandFromError(err error) UnifiedCommand {
|
||||
return UnifiedCommand{
|
||||
Action: "error",
|
||||
Message: err.Error(),
|
||||
}
|
||||
}
|
||||
|
||||
func (v UnifiedCommand) Marshal() []byte {
|
||||
data, _ := jsoniter.Marshal(v)
|
||||
return data
|
||||
}
|
8
pkg/models/utils.go
Normal file
8
pkg/models/utils.go
Normal file
@ -0,0 +1,8 @@
|
||||
package models
|
||||
|
||||
import jsoniter "github.com/json-iterator/go"
|
||||
|
||||
func FitStruct(src any, out any) {
|
||||
raw, _ := jsoniter.Marshal(src)
|
||||
_ = jsoniter.Unmarshal(raw, out)
|
||||
}
|
Reference in New Issue
Block a user