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

@@ -8,6 +8,7 @@ import (
"strings"
"time"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/db"
"github.com/owncast/owncast/utils"
@@ -70,7 +71,7 @@ func CreateAnonymousUser(displayName string) (*User, string, error) {
}
}
displayColor := utils.GenerateRandomDisplayColor()
displayColor := utils.GenerateRandomDisplayColor(config.MaxUserColor)
user := &User{
ID: id,
@@ -125,6 +126,21 @@ func ChangeUsername(userID string, username string) error {
return nil
}
// ChangeUserColor will change the user associated to userID from one display name to another.
func ChangeUserColor(userID string, color int) error {
_datastore.DbLock.Lock()
defer _datastore.DbLock.Unlock()
if err := _datastore.GetQueries().ChangeDisplayColor(context.Background(), db.ChangeDisplayColorParams{
DisplayColor: int32(color),
ID: userID,
}); err != nil {
return errors.Wrap(err, "unable to change display color")
}
return nil
}
func addAccessTokenForUser(accessToken, userID string) error {
return _datastore.GetQueries().AddAccessTokenForUser(context.Background(), db.AddAccessTokenForUserParams{
Token: accessToken,