2024-01-06 17:56:32 +00:00
|
|
|
package models
|
|
|
|
|
2024-01-07 07:52:23 +00:00
|
|
|
import (
|
2024-05-22 15:45:43 +00:00
|
|
|
"fmt"
|
2024-01-07 07:52:23 +00:00
|
|
|
"time"
|
2024-03-20 12:56:07 +00:00
|
|
|
|
|
|
|
"github.com/samber/lo"
|
2024-05-22 15:45:43 +00:00
|
|
|
"github.com/spf13/viper"
|
2024-05-17 09:13:11 +00:00
|
|
|
"gorm.io/datatypes"
|
2024-01-07 07:52:23 +00:00
|
|
|
)
|
2024-01-06 17:56:32 +00:00
|
|
|
|
|
|
|
type Account struct {
|
|
|
|
BaseModel
|
|
|
|
|
2024-05-17 09:13:11 +00:00
|
|
|
Name string `json:"name" gorm:"uniqueIndex"`
|
|
|
|
Nick string `json:"nick"`
|
|
|
|
Description string `json:"description"`
|
2024-05-20 14:41:54 +00:00
|
|
|
Avatar *uint `json:"avatar"`
|
|
|
|
Banner *uint `json:"banner"`
|
2024-05-17 09:13:11 +00:00
|
|
|
ConfirmedAt *time.Time `json:"confirmed_at"`
|
|
|
|
PermNodes datatypes.JSONMap `json:"perm_nodes"`
|
2024-04-05 17:07:36 +00:00
|
|
|
|
2024-05-04 03:15:13 +00:00
|
|
|
Profile AccountProfile `json:"profile"`
|
|
|
|
PersonalPage AccountPage `json:"personal_page"`
|
2024-06-02 12:15:04 +00:00
|
|
|
Badges []Badge `json:"badges"`
|
2024-05-04 03:15:13 +00:00
|
|
|
Contacts []AccountContact `json:"contacts"`
|
|
|
|
RealmIdentities []RealmMember `json:"realm_identities"`
|
2024-04-05 17:07:36 +00:00
|
|
|
|
2024-04-21 04:20:06 +00:00
|
|
|
Tickets []AuthTicket `json:"tickets"`
|
|
|
|
Factors []AuthFactor `json:"factors"`
|
2024-04-05 17:07:36 +00:00
|
|
|
|
|
|
|
Events []ActionEvent `json:"events"`
|
|
|
|
MagicTokens []MagicToken `json:"-" gorm:"foreignKey:AssignTo"`
|
|
|
|
|
|
|
|
ThirdClients []ThirdClient `json:"clients"`
|
|
|
|
|
2024-02-07 15:15:16 +00:00
|
|
|
Notifications []Notification `json:"notifications" gorm:"foreignKey:RecipientID"`
|
|
|
|
NotifySubscribers []NotificationSubscriber `json:"notify_subscribers"`
|
2024-04-05 17:07:36 +00:00
|
|
|
|
|
|
|
Friendships []AccountFriendship `json:"friendships" gorm:"foreignKey:AccountID"`
|
|
|
|
RelatedFriendships []AccountFriendship `json:"related_friendships" gorm:"foreignKey:RelatedID"`
|
2024-01-06 17:56:32 +00:00
|
|
|
}
|
|
|
|
|
2024-05-22 15:45:43 +00:00
|
|
|
func (v Account) GetAvatar() *string {
|
|
|
|
if v.Avatar != nil {
|
|
|
|
return lo.ToPtr(fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), *v.Avatar))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Account) GetBanner() *string {
|
|
|
|
if v.Banner != nil {
|
|
|
|
return lo.ToPtr(fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), *v.Banner))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-28 16:32:39 +00:00
|
|
|
func (v Account) GetPrimaryEmail() AccountContact {
|
|
|
|
val, _ := lo.Find(v.Contacts, func(item AccountContact) bool {
|
|
|
|
return item.Type == EmailAccountContact && item.IsPrimary
|
|
|
|
})
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
2024-01-06 17:56:32 +00:00
|
|
|
type AccountContactType = int8
|
|
|
|
|
|
|
|
const (
|
|
|
|
EmailAccountContact = AccountContactType(iota)
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountContact struct {
|
|
|
|
BaseModel
|
|
|
|
|
|
|
|
Type int8 `json:"type"`
|
|
|
|
Content string `json:"content" gorm:"uniqueIndex"`
|
|
|
|
IsPublic bool `json:"is_public"`
|
|
|
|
IsPrimary bool `json:"is_primary"`
|
|
|
|
VerifiedAt *time.Time `json:"verified_at"`
|
|
|
|
AccountID uint `json:"account_id"`
|
|
|
|
}
|