Update user.go
Cette révision appartient à :
Parent
7ca100ac9b
révision
cfec84010c
1 fichiers modifiés avec 0 ajouts et 27 suppressions
|
@ -12,8 +12,6 @@ import (
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
"github.com/NyaaPantsu/nyaa/utils/crypto"
|
"github.com/NyaaPantsu/nyaa/utils/crypto"
|
||||||
)
|
)
|
||||||
|
@ -47,7 +45,6 @@ type User struct {
|
||||||
Mascot string `gorm:"column:mascot"`
|
Mascot string `gorm:"column:mascot"`
|
||||||
MascotURL string `gorm:"column:mascot_url"`
|
MascotURL string `gorm:"column:mascot_url"`
|
||||||
UserSettings string `gorm:"column:settings"`
|
UserSettings string `gorm:"column:settings"`
|
||||||
Pantsu float64 `gorm:"column:pantsu"`
|
|
||||||
|
|
||||||
// TODO: move this to PublicUser
|
// TODO: move this to PublicUser
|
||||||
Followers []User // Don't work `gorm:"foreignkey:user_id;associationforeignkey:follower_id;many2many:user_follows"`
|
Followers []User // Don't work `gorm:"foreignkey:user_id;associationforeignkey:follower_id;many2many:user_follows"`
|
||||||
|
@ -59,7 +56,6 @@ type User struct {
|
||||||
|
|
||||||
UnreadNotifications int `gorm:"-"` // We don't want to loop every notifications when accessing user unread notif
|
UnreadNotifications int `gorm:"-"` // We don't want to loop every notifications when accessing user unread notif
|
||||||
Settings UserSettings `gorm:"-"` // We don't want to load settings everytime, stock it as a string, parse it when needed
|
Settings UserSettings `gorm:"-"` // We don't want to load settings everytime, stock it as a string, parse it when needed
|
||||||
Tags []Tag `gorm:"-"` // We load tags only when viewing a torrent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserJSON : User model conversion in JSON
|
// UserJSON : User model conversion in JSON
|
||||||
|
@ -397,26 +393,3 @@ func (u *User) Filter() *User {
|
||||||
u.Torrents = torrents
|
u.Torrents = torrents
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
// IncreasePantsu is a function that uses the formula to increase the Pantsu points of a user
|
|
||||||
func (u *User) IncreasePantsu() {
|
|
||||||
if u.Pantsu <= 0 {
|
|
||||||
u.Pantsu = 1 // Pantsu points should never be less or equal to 0. This would trigger a division by 0
|
|
||||||
}
|
|
||||||
u.Pantsu = u.Pantsu * (1 + 1/(math.Pow(math.Log(u.Pantsu+1), 5))) // First votes substancially increases the vote, further it increase slowly
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecreasePantsu is a function that uses the formula to decrease the Pantsu points of a user
|
|
||||||
func (u *User) DecreasePantsu() {
|
|
||||||
u.Pantsu = 0.8 * u.Pantsu // You lose 20% of your pantsu points each wrong vote
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *User) LoadTags(torrent *Torrent) {
|
|
||||||
if u.ID == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := ORM.Where("torrent_id = ? AND user_id = ?", torrent.ID, u.ID).Find(&u.Tags).Error; err != nil {
|
|
||||||
log.CheckErrorWithMessage(err, "LOAD_TAGS_ERROR: Couldn't load tags!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Référencer dans un nouveau ticket