start point of hotlist support (untested)

This commit is contained in:
2026-01-25 22:47:28 -07:00
parent c5b2c3d64b
commit 0dd66709d9
6 changed files with 114 additions and 20 deletions
+48 -1
View File
@@ -1,6 +1,6 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
* Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -9,9 +9,56 @@
// The database package contains database management and storage logic.
package database
import "context"
// ConferenceHotlist represents a user's conference hotlist.
type ConferenceHotlist struct {
Uid int32 `db:"uid"`
Sequence int16 `db:"sequence"`
CommId int32 `db:"commid"`
ConfId int32 `db:"confid"`
}
// Community gets the community pointer from the hotlist.
func (h *ConferenceHotlist) Community(ctx context.Context) (*Community, error) {
return AmGetCommunity(ctx, h.CommId)
}
// Conference gets the conference pointer from the hotlist.
func (h *ConferenceHotlist) Conference(ctx context.Context) (*Conference, error) {
return AmGetConference(ctx, h.ConfId)
}
// AmGetConferenceHotlist gets the conference hotlist for a user.
func AmGetConferenceHotlist(ctx context.Context, u *User) ([]ConferenceHotlist, error) {
var rc []ConferenceHotlist
err := amdb.SelectContext(ctx, &rc, "SELECT * FROM confhotlist WHERE uid = ? ORDER BY sequence", u.Uid)
return rc, err
}
// AmCopyConferenceHotlist copies the conference hotlist from one user to another.
func AmCopyConferenceHotlist(ctx context.Context, from, to *User) error {
hotlist, err := AmGetConferenceHotlist(ctx, from)
if err != nil {
return err
}
success := false
tx := amdb.MustBegin()
defer func() {
if !success {
tx.Rollback()
}
}()
for _, hl := range hotlist {
if _, err = tx.ExecContext(ctx, "INSERT INTO confhotlist (uid, sequence, commid, confid) VALUES (?, ?, ?, ?)",
to.Uid, hl.Sequence, hl.CommId, hl.ConfId); err != nil {
return err
}
}
if err = tx.Commit(); err != nil {
return err
}
success = true
return nil
}
+7 -4
View File
@@ -680,7 +680,7 @@ func AmCreateNewUser(ctx context.Context, username string, password string, remi
defer func() {
AmStoreAudit(ar)
}()
anon, _ := getAnonUserID(ctx)
anon, _ := AmGetAnonUser(ctx)
success := false
tx := amdb.MustBegin()
defer func() {
@@ -728,7 +728,7 @@ func AmCreateNewUser(ctx context.Context, username string, password string, remi
// add user properties
props := make([]UserProperties, 0)
if err = tx.SelectContext(ctx, &props, "SELECT * FROM propuser WHERE uid = ?", anon); err != nil {
if err = tx.SelectContext(ctx, &props, "SELECT * FROM propuser WHERE uid = ?", anon.Uid); err != nil {
return nil, err
}
for _, p := range props {
@@ -739,7 +739,7 @@ func AmCreateNewUser(ctx context.Context, username string, password string, remi
}
// add user sideboxes
if err = copySideboxes(ctx, tx, user.Uid, anon); err != nil {
if err = copySideboxes(ctx, tx, user.Uid, anon.Uid); err != nil {
return nil, err
}
@@ -756,7 +756,10 @@ func AmCreateNewUser(ctx context.Context, username string, password string, remi
return nil, err
}
// TODO: copy conference hotlists
// copy conference hotlists
if err = AmCopyConferenceHotlist(ctx, anon, user); err != nil {
return nil, err
}
// operation was a success - add an audit record
ar = AmNewAudit(AuditAccountCreated, user.Uid, remoteIP)