diff --git a/cmd/core.go b/cmd/core.go index 5c7c10b..e95373e 100644 --- a/cmd/core.go +++ b/cmd/core.go @@ -152,17 +152,23 @@ func syncConfWithDB() { // 导入配置文件的管理员用户 for _, admin := range config.Instance.AdminUsers { user := model.FindUser(admin.Name, admin.Email) + receiveEmail := true // 默认允许接收邮件 + if admin.ReceiveEmail != nil { + receiveEmail = *admin.ReceiveEmail + } if user.IsEmpty() { // create user = model.User{ - Name: admin.Name, - Email: admin.Email, - Link: admin.Link, - Password: admin.Password, - BadgeName: admin.BadgeName, - BadgeColor: admin.BadgeColor, - IsAdmin: true, - IsInConf: true, + Name: admin.Name, + Email: admin.Email, + Link: admin.Link, + Password: admin.Password, + BadgeName: admin.BadgeName, + BadgeColor: admin.BadgeColor, + IsAdmin: true, + IsInConf: true, + ReceiveEmail: receiveEmail, + SiteNames: strings.Join(admin.Sites, ","), } model.CreateUser(&user) } else { @@ -175,6 +181,8 @@ func syncConfWithDB() { user.BadgeColor = admin.BadgeColor user.IsAdmin = true user.IsInConf = true + user.ReceiveEmail = receiveEmail + user.SiteNames = strings.Join(admin.Sites, ",") model.UpdateUser(&user) } } diff --git a/config/config.go b/config/config.go index 0fb627c..0272676 100644 --- a/config/config.go +++ b/config/config.go @@ -76,12 +76,14 @@ type SSLConf struct { } type AdminUserConf struct { - Name string `mapstructure:"name" json:"name"` - Email string `mapstructure:"email" json:"email"` - Link string `mapstructure:"link" json:"link"` - Password string `mapstructure:"password" json:"password"` - BadgeName string `mapstructure:"badge_name" json:"badge_name"` - BadgeColor string `mapstructure:"badge_color" json:"badge_color"` + Name string `mapstructure:"name" json:"name"` + Email string `mapstructure:"email" json:"email"` + Link string `mapstructure:"link" json:"link"` + Password string `mapstructure:"password" json:"password"` + BadgeName string `mapstructure:"badge_name" json:"badge_name"` + BadgeColor string `mapstructure:"badge_color" json:"badge_color"` + ReceiveEmail *bool `mapstructure:"receive_email" json:"receive_email"` + Sites []string `mapstructure:"sites" json:"sites"` } type ModeratorConf struct { diff --git a/model/notify_launcher/notify_launcher.go b/model/notify_launcher/notify_launcher.go index 252c8cb..a88ddcb 100644 --- a/model/notify_launcher/notify_launcher.go +++ b/model/notify_launcher/notify_launcher.go @@ -29,7 +29,8 @@ func SendNotify(comment *model.Comment, pComment *model.Comment) { // ============== // 回复对方 // ============== - if !comment.IsPending { // 待审状态评论禁止回复对方 + if !comment.IsPending && pComment.FetchUser().ReceiveEmail { + // 不是待审状态评论 && 对方开启接收邮件 notify := model.FindCreateNotify(pComment.UserID, comment.ID) notify.SetComment(*comment) notify.SetInitial() @@ -53,6 +54,16 @@ func SendNotify(comment *model.Comment, pComment *model.Comment) { continue } + // 只发送给对应站点管理员 + if admin.SiteNames != "" && !lib.ContainsStr(admin.ToCooked().SiteNames, comment.SiteName) { + continue + } + + // 关闭接收邮件 + if !admin.ReceiveEmail { + continue + } + notify := model.FindCreateNotify(admin.ID, comment.ID) notify.SetComment(*comment) notify.SetInitial() diff --git a/model/user.go b/model/user.go index fcba706..e2d10fa 100644 --- a/model/user.go +++ b/model/user.go @@ -1,20 +1,23 @@ package model import ( + "github.com/ArtalkJS/ArtalkGo/lib" "gorm.io/gorm" ) type User struct { gorm.Model - Name string `gorm:"index;size:255"` - Email string `gorm:"index;size:255"` - Link string - Password string - BadgeName string - BadgeColor string - LastIP string - LastUA string - IsAdmin bool + Name string `gorm:"index;size:255"` + Email string `gorm:"index;size:255"` + Link string + Password string + BadgeName string + BadgeColor string + LastIP string + LastUA string + IsAdmin bool + SiteNames string + ReceiveEmail bool `gorm:"default:true"` // 配置文件中添加的 IsInConf bool @@ -25,23 +28,31 @@ func (u User) IsEmpty() bool { } type CookedUser struct { - ID uint `json:"id"` - Name string `json:"name"` - Email string `json:"email"` - Link string `json:"link"` - BadgeName string `json:"badge_name"` - BadgeColor string `json:"badge_color"` - IsAdmin bool `json:"is_admin"` + ID uint `json:"id"` + Name string `json:"name"` + Email string `json:"email"` + Link string `json:"link"` + BadgeName string `json:"badge_name"` + BadgeColor string `json:"badge_color"` + IsAdmin bool `json:"is_admin"` + SiteNames []string `json:"site_names"` + SiteNamesRaw string `json:"site_names_raw"` + ReceiveEmail bool `json:"receive_email"` } func (u User) ToCooked() CookedUser { + splitSites := lib.RemoveBlankStrings(lib.SplitAndTrimSpace(u.SiteNames, ",")) + return CookedUser{ - ID: u.ID, - Name: u.Name, - Email: u.Email, - Link: u.Link, - BadgeName: u.BadgeName, - BadgeColor: u.BadgeColor, - IsAdmin: u.IsAdmin, + ID: u.ID, + Name: u.Name, + Email: u.Email, + Link: u.Link, + BadgeName: u.BadgeName, + BadgeColor: u.BadgeColor, + IsAdmin: u.IsAdmin, + SiteNames: splitSites, + SiteNamesRaw: u.SiteNames, + ReceiveEmail: u.ReceiveEmail, } }