feat: 后台增加开放消息开关
关闭后前台隐藏私聊/群聊入口并由后端拦截;同步去掉公告页重复计数胶囊。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -21,7 +21,9 @@ const (
|
||||
SettingKeySiteDescription = "site_description"
|
||||
SettingKeyAllowRegister = "allow_register"
|
||||
// SettingKeyAllowComments 全站开放评论;缺行视为开启(默认开)
|
||||
SettingKeyAllowComments = "allow_comments"
|
||||
SettingKeyAllowComments = "allow_comments"
|
||||
// SettingKeyAllowMessages 全站开放私聊/群聊;缺行视为开启(默认开)
|
||||
SettingKeyAllowMessages = "allow_messages"
|
||||
SettingKeyPostCooldownHours = "post_cooldown_hours"
|
||||
// SettingKeyCodeBlockAutoFold 代码块自动折叠;缺行视为开启
|
||||
SettingKeyCodeBlockAutoFold = "code_block_auto_fold"
|
||||
@@ -61,20 +63,21 @@ var accentHexRe = regexp.MustCompile(`^#[0-9a-fA-F]{6}$`)
|
||||
|
||||
// PublicSiteSettings 对前台公开的站点配置(SEO / 注册入口 / 发帖冷静期提示)
|
||||
type PublicSiteSettings struct {
|
||||
Accent string `json:"accent"`
|
||||
TrustReviewedPublish bool `json:"trust_reviewed_publish"`
|
||||
SiteName string `json:"site_name"`
|
||||
SiteDescription string `json:"site_description"`
|
||||
AllowRegister bool `json:"allow_register"`
|
||||
AllowComments bool `json:"allow_comments"`
|
||||
PostCooldownHours int `json:"post_cooldown_hours"`
|
||||
CodeBlockAutoFold bool `json:"code_block_auto_fold"`
|
||||
CodeBlockFoldLines int `json:"code_block_fold_lines"`
|
||||
UIAnimations bool `json:"ui_animations"`
|
||||
AnimCodeFold bool `json:"anim_code_fold"`
|
||||
AnimSmoothScroll bool `json:"anim_smooth_scroll"`
|
||||
AnimChrome bool `json:"anim_chrome"`
|
||||
PostLinkNewTab bool `json:"post_link_new_tab"`
|
||||
Accent string `json:"accent"`
|
||||
TrustReviewedPublish bool `json:"trust_reviewed_publish"`
|
||||
SiteName string `json:"site_name"`
|
||||
SiteDescription string `json:"site_description"`
|
||||
AllowRegister bool `json:"allow_register"`
|
||||
AllowComments bool `json:"allow_comments"`
|
||||
AllowMessages bool `json:"allow_messages"`
|
||||
PostCooldownHours int `json:"post_cooldown_hours"`
|
||||
CodeBlockAutoFold bool `json:"code_block_auto_fold"`
|
||||
CodeBlockFoldLines int `json:"code_block_fold_lines"`
|
||||
UIAnimations bool `json:"ui_animations"`
|
||||
AnimCodeFold bool `json:"anim_code_fold"`
|
||||
AnimSmoothScroll bool `json:"anim_smooth_scroll"`
|
||||
AnimChrome bool `json:"anim_chrome"`
|
||||
PostLinkNewTab bool `json:"post_link_new_tab"`
|
||||
}
|
||||
|
||||
// SettingService 站点级键值设置
|
||||
@@ -135,6 +138,7 @@ func (s *SettingService) Public() (PublicSiteSettings, error) {
|
||||
TrustReviewedPublish: true,
|
||||
AllowRegister: true,
|
||||
AllowComments: true,
|
||||
AllowMessages: true,
|
||||
PostCooldownHours: DefaultCooldownHours,
|
||||
CodeBlockAutoFold: true,
|
||||
CodeBlockFoldLines: DefaultCodeFoldLines,
|
||||
@@ -187,6 +191,12 @@ func (s *SettingService) Public() (PublicSiteSettings, error) {
|
||||
}
|
||||
out.AllowComments = comments
|
||||
|
||||
messages, err := s.AllowMessages()
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out.AllowMessages = messages
|
||||
|
||||
hours, err := s.PostCooldownHours()
|
||||
if err != nil {
|
||||
return out, err
|
||||
@@ -320,6 +330,20 @@ func (s *SettingService) SetAllowComments(on bool) error {
|
||||
return s.setBoolDefaultTrue(SettingKeyAllowComments, on)
|
||||
}
|
||||
|
||||
// AllowMessages 是否允许全站私聊/群聊。缺行视为开启。
|
||||
func (s *SettingService) AllowMessages() (bool, error) {
|
||||
v, found, err := s.getValue(SettingKeyAllowMessages)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return parseBoolDefaultTrue(v, found), nil
|
||||
}
|
||||
|
||||
// SetAllowMessages 持久化消息开关;开启时删键保持「缺行=默认开」。
|
||||
func (s *SettingService) SetAllowMessages(on bool) error {
|
||||
return s.setBoolDefaultTrue(SettingKeyAllowMessages, on)
|
||||
}
|
||||
|
||||
// PostCooldownHours 新用户发帖冷静期(小时)。缺行=24;0 表示关闭。
|
||||
func (s *SettingService) PostCooldownHours() (int, error) {
|
||||
v, found, err := s.getValue(SettingKeyPostCooldownHours)
|
||||
|
||||
Reference in New Issue
Block a user