⬆️ Upgrade to support the latest version Hydrogen Project standard
This commit is contained in:
18
pkg/internal/models/accounts.go
Normal file
18
pkg/internal/models/accounts.go
Normal file
@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
// Account profiles basically fetched from Hydrogen.Identity
|
||||
// But cache at here for better usage
|
||||
// At the same time this model can make relations between local models
|
||||
type Account struct {
|
||||
BaseModel
|
||||
|
||||
Name string `json:"name"`
|
||||
Nick string `json:"nick"`
|
||||
Avatar string `json:"avatar"`
|
||||
Banner string `json:"banner"`
|
||||
Description string `json:"description"`
|
||||
EmailAddress string `json:"email_address"`
|
||||
PowerLevel int `json:"power_level"`
|
||||
Channels []Channel `json:"channels"`
|
||||
ExternalID uint `json:"external_id"`
|
||||
}
|
17
pkg/internal/models/base.go
Normal file
17
pkg/internal/models/base.go
Normal file
@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type JSONMap = datatypes.JSONType[map[string]any]
|
||||
|
||||
type BaseModel struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
}
|
15
pkg/internal/models/calls.go
Normal file
15
pkg/internal/models/calls.go
Normal file
@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Call struct {
|
||||
BaseModel
|
||||
|
||||
EndedAt *time.Time `json:"ended_at"`
|
||||
|
||||
ExternalID string `json:"external_id"`
|
||||
FounderID uint `json:"founder_id"`
|
||||
ChannelID uint `json:"channel_id"`
|
||||
Founder ChannelMember `json:"founder"`
|
||||
Channel Channel `json:"channel"`
|
||||
}
|
49
pkg/internal/models/channels.go
Normal file
49
pkg/internal/models/channels.go
Normal file
@ -0,0 +1,49 @@
|
||||
package models
|
||||
|
||||
type ChannelType = uint8
|
||||
|
||||
const (
|
||||
ChannelTypeCommon = ChannelType(iota)
|
||||
ChannelTypeDirect
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
BaseModel
|
||||
|
||||
Alias string `json:"alias"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Members []ChannelMember `json:"members"`
|
||||
Messages []Message `json:"messages"`
|
||||
Calls []Call `json:"calls"`
|
||||
Type ChannelType `json:"type"`
|
||||
Account Account `json:"account"`
|
||||
AccountID uint `json:"account_id"`
|
||||
IsEncrypted bool `json:"is_encrypted"`
|
||||
|
||||
Realm Realm `json:"realm"`
|
||||
RealmID *uint `json:"realm_id"`
|
||||
}
|
||||
|
||||
type NotifyLevel = int8
|
||||
|
||||
const (
|
||||
NotifyLevelAll = NotifyLevel(iota)
|
||||
NotifyLevelMentioned
|
||||
NotifyLevelNone
|
||||
)
|
||||
|
||||
type ChannelMember struct {
|
||||
BaseModel
|
||||
|
||||
ChannelID uint `json:"channel_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
Nick *string `json:"nick"`
|
||||
Channel Channel `json:"channel"`
|
||||
Account Account `json:"account"`
|
||||
Notify NotifyLevel `json:"notify"`
|
||||
PowerLevel int `json:"power_level"`
|
||||
|
||||
Calls []Call `json:"calls" gorm:"foreignKey:FounderID"`
|
||||
Messages []Message `json:"messages" gorm:"foreignKey:SenderID"`
|
||||
}
|
22
pkg/internal/models/messages.go
Normal file
22
pkg/internal/models/messages.go
Normal file
@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import "gorm.io/datatypes"
|
||||
|
||||
const (
|
||||
MessageTextType = "m.text"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
BaseModel
|
||||
|
||||
Uuid string `json:"uuid"`
|
||||
Content datatypes.JSONMap `json:"content"`
|
||||
Type string `json:"type"`
|
||||
Attachments datatypes.JSONSlice[uint] `json:"attachments"`
|
||||
Channel Channel `json:"channel"`
|
||||
Sender ChannelMember `json:"sender"`
|
||||
ReplyID *uint `json:"reply_id"`
|
||||
ReplyTo *Message `json:"reply_to" gorm:"foreignKey:ReplyID"`
|
||||
ChannelID uint `json:"channel_id"`
|
||||
SenderID uint `json:"sender_id"`
|
||||
}
|
15
pkg/internal/models/realms.go
Normal file
15
pkg/internal/models/realms.go
Normal file
@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
// Realm profiles basically fetched from Hydrogen.Passport
|
||||
// But cache at here for better usage and database relations
|
||||
type Realm struct {
|
||||
BaseModel
|
||||
|
||||
Alias string `json:"alias"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Channels []Channel `json:"channels"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
IsCommunity bool `json:"is_community"`
|
||||
ExternalID uint `json:"external_id"`
|
||||
}
|
21
pkg/internal/models/unified.go
Normal file
21
pkg/internal/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/internal/models/utils.go
Normal file
8
pkg/internal/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