mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +03:00
Limit chat display names to 30 characters. Closes #1919
This commit is contained in:
parent
c93d4fca08
commit
d32d741abf
2 changed files with 10 additions and 2 deletions
|
@ -13,6 +13,8 @@ const (
|
||||||
DataDirectory = "data"
|
DataDirectory = "data"
|
||||||
// EmojiDir is relative to the webroot.
|
// EmojiDir is relative to the webroot.
|
||||||
EmojiDir = "/img/emoji"
|
EmojiDir = "/img/emoji"
|
||||||
|
// MaxChatDisplayNameLength is the maximum length of a chat display name.
|
||||||
|
MaxChatDisplayNameLength = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/owncast/owncast/config"
|
||||||
"github.com/owncast/owncast/core/chat/events"
|
"github.com/owncast/owncast/core/chat/events"
|
||||||
"github.com/owncast/owncast/core/data"
|
"github.com/owncast/owncast/core/data"
|
||||||
"github.com/owncast/owncast/core/user"
|
"github.com/owncast/owncast/core/user"
|
||||||
|
@ -25,6 +26,11 @@ func (s *Server) userNameChanged(eventData chatClientEvent) {
|
||||||
// Check if name is on the blocklist
|
// Check if name is on the blocklist
|
||||||
blocklist := data.GetForbiddenUsernameList()
|
blocklist := data.GetForbiddenUsernameList()
|
||||||
|
|
||||||
|
// Names have a max length
|
||||||
|
if len(proposedUsername) > config.MaxChatDisplayNameLength {
|
||||||
|
proposedUsername = proposedUsername[:config.MaxChatDisplayNameLength]
|
||||||
|
}
|
||||||
|
|
||||||
for _, blockedName := range blocklist {
|
for _, blockedName := range blocklist {
|
||||||
normalizedName := strings.TrimSpace(blockedName)
|
normalizedName := strings.TrimSpace(blockedName)
|
||||||
normalizedName = strings.ToLower(normalizedName)
|
normalizedName = strings.ToLower(normalizedName)
|
||||||
|
@ -59,7 +65,7 @@ func (s *Server) userNameChanged(eventData chatClientEvent) {
|
||||||
oldName := savedUser.DisplayName
|
oldName := savedUser.DisplayName
|
||||||
|
|
||||||
// Save the new name
|
// Save the new name
|
||||||
if err := user.ChangeUsername(eventData.client.User.ID, receivedEvent.NewName); err != nil {
|
if err := user.ChangeUsername(eventData.client.User.ID, proposedUsername); err != nil {
|
||||||
log.Errorln("error changing username", err)
|
log.Errorln("error changing username", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +75,7 @@ func (s *Server) userNameChanged(eventData chatClientEvent) {
|
||||||
eventData.client.User.NameChangedAt = &now
|
eventData.client.User.NameChangedAt = &now
|
||||||
|
|
||||||
// Send chat event letting everyone about about the name change
|
// Send chat event letting everyone about about the name change
|
||||||
savedUser.DisplayName = receivedEvent.NewName
|
savedUser.DisplayName = proposedUsername
|
||||||
|
|
||||||
broadcastEvent := events.NameChangeBroadcast{
|
broadcastEvent := events.NameChangeBroadcast{
|
||||||
Oldname: oldName,
|
Oldname: oldName,
|
||||||
|
|
Loading…
Reference in a new issue