mod todo, add mod appearence, about for user

This commit is contained in:
2026-04-04 12:14:15 +02:00
parent a7c58f4037
commit 91220c37ca
4 changed files with 77 additions and 12 deletions
+22 -4
View File
@@ -20,9 +20,9 @@ func DbInit(ctx context.Context) {
_, err = dbConn.Exec(ctx, `
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
name VARCHAR(20) UNIQUE NOT NULL,
pass_hash VARCHAR(60) NOT NULL,
pronouns VARCHAR(15) DEFAULT NULL,
name TEXT UNIQUE NOT NULL,
pass_hash TEXT NOT NULL,
pronouns TEXT DEFAULT NULL,
color_red SMALLINT DEFAULT NULL,
color_green SMALLINT DEFAULT NULL,
color_blue SMALLINT DEFAULT NULL,
@@ -36,7 +36,7 @@ func DbInit(ctx context.Context) {
_, err = dbConn.Exec(ctx, `
CREATE TABLE IF NOT EXISTS chat_groups (
id SERIAL PRIMARY KEY,
name VARCHAR(48) NOT NULL,
name TEXT NOT NULL,
creator_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
enable_client_colors BOOLEAN NOT NULL DEFAULT true,
@@ -137,6 +137,24 @@ func DbUserSetGroups(ctx context.Context, user *User) error {
return rows.Err()
}
// DbUserSetColor set user's color based on id
// return: error if not successful
func DbUserSetColor(ctx context.Context, user *User) error {
_, err := dbConn.Exec(ctx, `
UPDATE users SET color_red = $1, color_green = $2, color_blue = $3 WHERE id = $4
`, user.Color[0], user.Color[1], user.Color[2], user.Id)
return err
}
// DbUserSetPronouns set user's pronouns based on id
// return: error if not successful
func DbUserSetPronouns(ctx context.Context, user *User) error {
_, err := dbConn.Exec(ctx, `
UPDATE users SET pronouns = $1 WHERE id = $2
`, user.Pronouns, user.Id)
return err
}
// DbGroupSetColor set group's color based on id
// return: error if not successful
func DbGroupSetColor(ctx context.Context, group *Group) error {