62 lines
1.4 KiB
Go
Raw Normal View History

2024-03-26 23:05:13 +08:00
package models
2024-07-20 16:02:16 +08:00
import "fmt"
2024-03-30 17:10:36 +08:00
type ChannelType = uint8
const (
2024-05-26 23:01:20 +08:00
ChannelTypeCommon = ChannelType(iota)
ChannelTypeDirect
2024-03-30 17:10:36 +08:00
)
2024-03-26 23:05:13 +08:00
type Channel struct {
BaseModel
2024-05-05 00:39:59 +08:00
Alias string `json:"alias"`
2024-03-26 23:05:13 +08:00
Name string `json:"name"`
Description string `json:"description"`
Members []ChannelMember `json:"members"`
Messages []Event `json:"messages"`
2024-04-06 17:08:01 +08:00
Calls []Call `json:"calls"`
2024-03-30 17:10:36 +08:00
Type ChannelType `json:"type"`
2024-03-31 01:27:41 +08:00
Account Account `json:"account"`
2024-03-26 23:05:13 +08:00
AccountID uint `json:"account_id"`
2024-05-12 22:00:22 +08:00
IsEncrypted bool `json:"is_encrypted"`
Realm Realm `json:"realm"`
RealmID *uint `json:"realm_id"`
2024-03-26 23:05:13 +08:00
}
2024-07-20 16:02:16 +08:00
func (v Channel) DisplayText() string {
if v.Type == ChannelTypeDirect {
return "DM"
}
if v.RealmID != nil {
return fmt.Sprintf("%s, %s", v.Alias, v.Realm.Alias)
}
return fmt.Sprintf("%s", v.Alias)
2024-07-20 16:02:16 +08:00
}
2024-04-06 16:08:33 +08:00
type NotifyLevel = int8
const (
NotifyLevelAll = NotifyLevel(iota)
NotifyLevelMentioned
NotifyLevelNone
)
2024-03-26 23:05:13 +08:00
type ChannelMember struct {
BaseModel
2024-05-26 23:01:20 +08:00
ChannelID uint `json:"channel_id"`
AccountID uint `json:"account_id"`
Nick *string `json:"nick"`
2024-05-26 23:01:20 +08:00
Channel Channel `json:"channel"`
Account Account `json:"account"`
Notify NotifyLevel `json:"notify"`
PowerLevel int `json:"power_level"`
2024-03-30 17:10:36 +08:00
Calls []Call `json:"calls" gorm:"foreignKey:FounderID"`
Events []Event `json:"events" gorm:"foreignKey:SenderID"`
2024-03-26 23:05:13 +08:00
}