Browse Source

Add support to disable chat join messages. Closes #1582 (#1743)

pull/1682/head
Gabe Kangas 4 years ago committed by GitHub
parent
commit
d5a6267b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      controllers/admin/config.go
  2. 46
      controllers/admin/serverConfig.go
  3. 2
      core/chat/server.go
  4. 16
      core/data/config.go
  5. 3
      router/router.go

20
controllers/admin/config.go

@ -664,6 +664,26 @@ func SetSuggestedUsernameList(w http.ResponseWriter, r *http.Request) {
controllers.WriteSimpleResponse(w, true, "suggested username list updated") controllers.WriteSimpleResponse(w, true, "suggested username list updated")
} }
// SetChatJoinMessagesEnabled will enable or disable the chat join messages.
func SetChatJoinMessagesEnabled(w http.ResponseWriter, r *http.Request) {
if !requirePOST(w, r) {
return
}
configValue, success := getValueFromRequest(w, r)
if !success {
controllers.WriteSimpleResponse(w, false, "unable to update chat join messages enabled")
return
}
if err := data.SetChatJoinMessagesEnabled(configValue.Value.(bool)); err != nil {
controllers.WriteSimpleResponse(w, false, err.Error())
return
}
controllers.WriteSimpleResponse(w, true, "chat join message status updated")
}
func requirePOST(w http.ResponseWriter, r *http.Request) bool { func requirePOST(w http.ResponseWriter, r *http.Request) bool {
if r.Method != controllers.POST { if r.Method != controllers.POST {
controllers.WriteSimpleResponse(w, false, r.Method+" not supported") controllers.WriteSimpleResponse(w, false, r.Method+" not supported")

46
controllers/admin/serverConfig.go

@ -46,12 +46,13 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
NSFW: data.GetNSFW(), NSFW: data.GetNSFW(),
CustomStyles: data.GetCustomStyles(), CustomStyles: data.GetCustomStyles(),
}, },
FFmpegPath: ffmpeg, FFmpegPath: ffmpeg,
StreamKey: data.GetStreamKey(), StreamKey: data.GetStreamKey(),
WebServerPort: config.WebServerPort, WebServerPort: config.WebServerPort,
WebServerIP: config.WebServerIP, WebServerIP: config.WebServerIP,
RTMPServerPort: data.GetRTMPPortNumber(), RTMPServerPort: data.GetRTMPPortNumber(),
ChatDisabled: data.GetChatDisabled(), ChatDisabled: data.GetChatDisabled(),
ChatJoinMessagesEnabled: data.GetChatJoinMessagesEnabled(),
VideoSettings: videoSettings{ VideoSettings: videoSettings{
VideoQualityVariants: videoQualityVariants, VideoQualityVariants: videoQualityVariants,
LatencyLevel: data.GetStreamLatencyLevel().Level, LatencyLevel: data.GetStreamLatencyLevel().Level,
@ -85,22 +86,23 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
} }
type serverConfigAdminResponse struct { type serverConfigAdminResponse struct {
InstanceDetails webConfigResponse `json:"instanceDetails"` InstanceDetails webConfigResponse `json:"instanceDetails"`
FFmpegPath string `json:"ffmpegPath"` FFmpegPath string `json:"ffmpegPath"`
StreamKey string `json:"streamKey"` StreamKey string `json:"streamKey"`
WebServerPort int `json:"webServerPort"` WebServerPort int `json:"webServerPort"`
WebServerIP string `json:"webServerIP"` WebServerIP string `json:"webServerIP"`
RTMPServerPort int `json:"rtmpServerPort"` RTMPServerPort int `json:"rtmpServerPort"`
S3 models.S3 `json:"s3"` S3 models.S3 `json:"s3"`
VideoSettings videoSettings `json:"videoSettings"` VideoSettings videoSettings `json:"videoSettings"`
YP yp `json:"yp"` YP yp `json:"yp"`
ChatDisabled bool `json:"chatDisabled"` ChatDisabled bool `json:"chatDisabled"`
ExternalActions []models.ExternalAction `json:"externalActions"` ChatJoinMessagesEnabled bool `json:"chatJoinMessagesEnabled"`
SupportedCodecs []string `json:"supportedCodecs"` ExternalActions []models.ExternalAction `json:"externalActions"`
VideoCodec string `json:"videoCodec"` SupportedCodecs []string `json:"supportedCodecs"`
ForbiddenUsernames []string `json:"forbiddenUsernames"` VideoCodec string `json:"videoCodec"`
Federation federationConfigResponse `json:"federation"` ForbiddenUsernames []string `json:"forbiddenUsernames"`
SuggestedUsernames []string `json:"suggestedUsernames"` Federation federationConfigResponse `json:"federation"`
SuggestedUsernames []string `json:"suggestedUsernames"`
} }
type videoSettings struct { type videoSettings struct {

2
core/chat/server.go

@ -91,7 +91,7 @@ func (s *Server) Addclient(conn *websocket.Conn, user *user.User, accessToken st
} }
// Do not send user re-joined broadcast message if they've been active within 5 minutes. // Do not send user re-joined broadcast message if they've been active within 5 minutes.
shouldSendJoinedMessages := true shouldSendJoinedMessages := data.GetChatJoinMessagesEnabled()
if previouslyLastSeen, ok := _lastSeenCache[user.ID]; ok && time.Since(previouslyLastSeen) < time.Minute*5 { if previouslyLastSeen, ok := _lastSeenCache[user.ID]; ok && time.Since(previouslyLastSeen) < time.Minute*5 {
shouldSendJoinedMessages = false shouldSendJoinedMessages = false
} }

16
core/data/config.go

@ -53,6 +53,7 @@ const (
federationShowEngagementKey = "federation_show_engagement" federationShowEngagementKey = "federation_show_engagement"
federationBlockedDomainsKey = "federation_blocked_domains" federationBlockedDomainsKey = "federation_blocked_domains"
suggestedUsernamesKey = "suggested_usernames" suggestedUsernamesKey = "suggested_usernames"
chatJoinMessagesEnabledKey = "chat_join_messages_enabled"
) )
// GetExtraPageBodyContent will return the user-supplied body content. // GetExtraPageBodyContent will return the user-supplied body content.
@ -754,3 +755,18 @@ func GetBlockedFederatedDomains() []string {
return strings.Split(domains, ",") return strings.Split(domains, ",")
} }
// SetChatJoinMessagesEnabled will set if chat join messages are enabled.
func SetChatJoinMessagesEnabled(enabled bool) error {
return _datastore.SetBool(chatJoinMessagesEnabledKey, enabled)
}
// GetChatJoinMessagesEnabled will return if chat join messages are enabled.
func GetChatJoinMessagesEnabled() bool {
enabled, err := _datastore.GetBool(chatJoinMessagesEnabledKey)
if err != nil {
return true
}
return enabled
}

3
router/router.go

@ -161,6 +161,9 @@ func Start() error {
// Disable chat // Disable chat
http.HandleFunc("/api/admin/config/chat/disable", middleware.RequireAdminAuth(admin.SetChatDisabled)) http.HandleFunc("/api/admin/config/chat/disable", middleware.RequireAdminAuth(admin.SetChatDisabled))
// Disable chat user join messages
http.HandleFunc("/api/admin/config/chat/joinmessagesenabled", middleware.RequireAdminAuth(admin.SetChatJoinMessagesEnabled))
// Set chat usernames that are not allowed // Set chat usernames that are not allowed
http.HandleFunc("/api/admin/config/chat/forbiddenusernames", middleware.RequireAdminAuth(admin.SetForbiddenUsernameList)) http.HandleFunc("/api/admin/config/chat/forbiddenusernames", middleware.RequireAdminAuth(admin.SetForbiddenUsernameList))

Loading…
Cancel
Save