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

This commit is contained in:
Gabe Kangas
2022-03-05 22:34:06 -08:00
committed by GitHub
parent 8692dcca16
commit d5a6267b1f
5 changed files with 64 additions and 23 deletions

View File

@@ -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.
shouldSendJoinedMessages := true
shouldSendJoinedMessages := data.GetChatJoinMessagesEnabled()
if previouslyLastSeen, ok := _lastSeenCache[user.ID]; ok && time.Since(previouslyLastSeen) < time.Minute*5 {
shouldSendJoinedMessages = false
}

View File

@@ -53,6 +53,7 @@ const (
federationShowEngagementKey = "federation_show_engagement"
federationBlockedDomainsKey = "federation_blocked_domains"
suggestedUsernamesKey = "suggested_usernames"
chatJoinMessagesEnabledKey = "chat_join_messages_enabled"
)
// GetExtraPageBodyContent will return the user-supplied body content.
@@ -754,3 +755,18 @@ func GetBlockedFederatedDomains() []string {
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
}