2024-03-26 15:05:13 +00:00
|
|
|
package models
|
|
|
|
|
2024-09-11 15:58:02 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2024-11-02 05:40:37 +00:00
|
|
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
|
|
|
|
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
2024-09-11 15:58:02 +00:00
|
|
|
)
|
2024-07-20 08:02:16 +00:00
|
|
|
|
2024-03-30 09:10:36 +00:00
|
|
|
type ChannelType = uint8
|
|
|
|
|
|
|
|
const (
|
2024-05-26 15:01:20 +00:00
|
|
|
ChannelTypeCommon = ChannelType(iota)
|
|
|
|
ChannelTypeDirect
|
2024-03-30 09:10:36 +00:00
|
|
|
)
|
|
|
|
|
2024-03-26 15:05:13 +00:00
|
|
|
type Channel struct {
|
2024-11-02 05:40:37 +00:00
|
|
|
cruda.BaseModel
|
2024-03-26 15:05:13 +00:00
|
|
|
|
2024-05-04 16:39:59 +00:00
|
|
|
Alias string `json:"alias"`
|
2024-03-26 15:05:13 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Members []ChannelMember `json:"members"`
|
2024-06-27 14:38:18 +00:00
|
|
|
Messages []Event `json:"messages"`
|
2024-04-06 09:08:01 +00:00
|
|
|
Calls []Call `json:"calls"`
|
2024-03-30 09:10:36 +00:00
|
|
|
Type ChannelType `json:"type"`
|
2024-03-26 15:05:13 +00:00
|
|
|
AccountID uint `json:"account_id"`
|
2024-09-17 03:45:44 +00:00
|
|
|
IsPublic bool `json:"is_public"`
|
|
|
|
IsCommunity bool `json:"is_community"`
|
2024-05-06 15:28:15 +00:00
|
|
|
|
2024-11-02 05:40:37 +00:00
|
|
|
Realm *authm.Realm `json:"realm" gorm:"-"`
|
|
|
|
RealmID *uint `json:"realm_id"`
|
2024-03-26 15:05:13 +00:00
|
|
|
}
|
|
|
|
|
2024-07-20 08:02:16 +00:00
|
|
|
func (v Channel) DisplayText() string {
|
|
|
|
if v.Type == ChannelTypeDirect {
|
|
|
|
return "DM"
|
|
|
|
}
|
2024-11-24 14:24:49 +00:00
|
|
|
if v.Realm != nil {
|
2024-08-01 04:03:34 +00:00
|
|
|
return fmt.Sprintf("%s, %s", v.Alias, v.Realm.Alias)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s", v.Alias)
|
2024-07-20 08:02:16 +00:00
|
|
|
}
|
|
|
|
|
2024-04-06 08:08:33 +00:00
|
|
|
type NotifyLevel = int8
|
|
|
|
|
|
|
|
const (
|
|
|
|
NotifyLevelAll = NotifyLevel(iota)
|
|
|
|
NotifyLevelMentioned
|
|
|
|
NotifyLevelNone
|
|
|
|
)
|
|
|
|
|
2024-03-26 15:05:13 +00:00
|
|
|
type ChannelMember struct {
|
2024-11-02 05:40:37 +00:00
|
|
|
cruda.BaseModel
|
2024-03-26 15:05:13 +00:00
|
|
|
|
2024-11-02 05:23:27 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Nick string `json:"nick"`
|
|
|
|
Avatar *string `json:"avatar"`
|
|
|
|
|
2024-05-26 15:01:20 +00:00
|
|
|
ChannelID uint `json:"channel_id"`
|
|
|
|
AccountID uint `json:"account_id"`
|
|
|
|
Channel Channel `json:"channel"`
|
|
|
|
Notify NotifyLevel `json:"notify"`
|
|
|
|
PowerLevel int `json:"power_level"`
|
2024-03-30 09:10:36 +00:00
|
|
|
|
2024-06-27 14:38:18 +00:00
|
|
|
Calls []Call `json:"calls" gorm:"foreignKey:FounderID"`
|
|
|
|
Events []Event `json:"events" gorm:"foreignKey:SenderID"`
|
2024-03-26 15:05:13 +00:00
|
|
|
}
|