Add support for changing user color in name modal. Closes #1805

This commit is contained in:
Gabe Kangas
2022-08-09 19:56:45 -07:00
parent 9187a7a435
commit 68414445c2
22 changed files with 171 additions and 55 deletions

View File

@@ -6,6 +6,7 @@ import (
"strings"
"time"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/chat/events"
"github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/core/user"
@@ -91,6 +92,25 @@ func (s *Server) userNameChanged(eventData chatClientEvent) {
eventData.client.sendConnectedClientInfo()
}
func (s *Server) userColorChanged(eventData chatClientEvent) {
var receivedEvent events.ColorChangeEvent
if err := json.Unmarshal(eventData.data, &receivedEvent); err != nil {
log.Errorln("error unmarshalling to ColorChangeEvent", err)
return
}
// Verify this color is valid
if receivedEvent.NewColor > config.MaxUserColor {
log.Errorln("invalid color requested when changing user display color")
return
}
// Save the new color
if err := user.ChangeUserColor(eventData.client.User.ID, receivedEvent.NewColor); err != nil {
log.Errorln("error changing user display color", err)
}
}
func (s *Server) userMessageSent(eventData chatClientEvent) {
var event events.UserMessageEvent
if err := json.Unmarshal(eventData.data, &event); err != nil {

View File

@@ -10,6 +10,8 @@ const (
UserJoined EventType = "USER_JOINED"
// UserNameChanged is the event sent when a chat username change takes place.
UserNameChanged EventType = "NAME_CHANGE"
// UserColorChanged is the event sent when a chat user color change takes place.
UserColorChanged EventType = "COLOR_CHANGE"
// VisibiltyUpdate is the event sent when a chat message's visibility changes.
VisibiltyUpdate EventType = "VISIBILITY-UPDATE"
// PING is a ping message.

View File

@@ -7,6 +7,13 @@ type NameChangeEvent struct {
NewName string `json:"newName"`
}
// ColorChangeEvent is received when a user changes their chat display color.
type ColorChangeEvent struct {
Event
UserEvent
NewColor int `json:"newColor"`
}
// NameChangeBroadcast represents a user changing their chat display name.
type NameChangeBroadcast struct {
Event

View File

@@ -359,6 +359,8 @@ func (s *Server) eventReceived(event chatClientEvent) {
case events.UserNameChanged:
s.userNameChanged(event)
case events.UserColorChanged:
s.userColorChanged(event)
default:
log.Debugln(eventType, "event not found:", typecheck)
}