feat: 后台增加开放消息开关
关闭后前台隐藏私聊/群聊入口并由后端拦截;同步去掉公告页重复计数胶囊。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -47,15 +47,33 @@ func (h *Handlers) chatOversee(userID uint) bool {
|
||||
return service.CanOverseeChat(actor.Role)
|
||||
}
|
||||
|
||||
// RequireMessagesOpen 前台群聊/私聊闸门;关闭后一律 403。管理端 /api/admin/chat 不受影响。
|
||||
func (h *Handlers) RequireMessagesOpen(c *gin.Context) {
|
||||
if h.Setting == nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "消息暂时不可用"})
|
||||
return
|
||||
}
|
||||
allow, err := h.Setting.AllowMessages()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "消息暂时不可用"})
|
||||
return
|
||||
}
|
||||
if !allow {
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "本站不支持消息"})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
|
||||
// CreateChatRoom 建群(可公开/私密,私密可带初始成员)
|
||||
func (h *Handlers) CreateChatRoom(c *gin.Context) {
|
||||
claims := middleware.CurrentUser(c)
|
||||
var req struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
IsPrivate bool `json:"is_private"`
|
||||
MemberIDs []uint `json:"member_ids"`
|
||||
MemberUsernames []string `json:"member_usernames"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
IsPrivate bool `json:"is_private"`
|
||||
MemberIDs []uint `json:"member_ids"`
|
||||
MemberUsernames []string `json:"member_usernames"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请求参数无效"})
|
||||
|
||||
Reference in New Issue
Block a user