some more work on add topic - we're up to where we need to branch off for an attachment

This commit is contained in:
2025-11-07 22:55:53 -07:00
parent 5dbff8b4b3
commit 944f22e963
3 changed files with 102 additions and 5 deletions
+20 -5
View File
@@ -44,6 +44,7 @@ func conferencesPrequel(ctxt ui.AmContext) (string, any, error) {
ctxt.SetRC(http.StatusForbidden)
return ui.ErrorPage(ctxt, errors.New("you are not authorized access to conferences"))
}
ctxt.SetLeftMenu("community")
return "", nil, nil
}
@@ -183,10 +184,6 @@ func NewTopicForm(ctxt ui.AmContext) (string, any, error) {
}
comm := ctxt.CurrentCommunity()
conf := ctxt.GetScratch("currentConference").(*database.Conference)
ci, err := ctxt.CurrentUser().ContactInfo()
if err != nil {
return ui.ErrorPage(ctxt, err)
}
myLevel := ctxt.GetScratch("levelInConference").(uint16)
if !conf.TestPermission("Conference.Create", myLevel) {
ctxt.SetRC(http.StatusForbidden)
@@ -195,7 +192,19 @@ func NewTopicForm(ctxt ui.AmContext) (string, any, error) {
ctxt.VarMap().Set("conferenceName", conf.Name)
ctxt.VarMap().Set("urlStem", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.URLParam("confid")))
ctxt.VarMap().Set("topicName", "")
ctxt.VarMap().Set("pseud", ci.FullName(false))
cs, err := conf.Settings(ctxt.CurrentUser())
if err != nil {
return ui.ErrorPage(ctxt, err)
}
if cs == nil || cs.DefaultPseud == nil {
ci, err := ctxt.CurrentUser().ContactInfo()
if err != nil {
return ui.ErrorPage(ctxt, err)
}
ctxt.VarMap().Set("pseud", ci.FullName(false))
} else {
ctxt.VarMap().Set("pseud", *cs.DefaultPseud)
}
ctxt.VarMap().Set("pb", "")
ctxt.VarMap().Set("amsterdam_pageTitle", "Create New Topic")
return "framed_template", "new_topic.jet", nil
@@ -295,6 +304,12 @@ func NewTopic(ctxt ui.AmContext) (string, any, error) {
if err != nil {
return ui.ErrorPage(ctxt, err)
}
if !ctxt.FormFieldIsSet("attach") {
return "redirect", urlStem, nil // no attachment - just redisplay topic list
}
// TODO: bounce to the attachment form
_ = topic // TODO
}
+76
View File
@@ -153,6 +153,82 @@ func (c *Conference) TestPermission(perm string, level uint16) bool {
}
}
// Settings returns the settings for a user.
func (c *Conference) Settings(u *User) (*ConferenceSettings, error) {
var dbdata []ConferenceSettings
err := amdb.Select(&dbdata, "SELECT * FROM confsettings WHERE confid = ? AND uid = ?", c.ConfId, u.Uid)
if err != nil {
return nil, err
}
if len(dbdata) == 0 {
return nil, nil
}
if len(dbdata) > 1 {
return nil, fmt.Errorf("conference.Settings(c=%d,u=%d): too many results (%d)", c.ConfId, u.Uid, len(dbdata))
}
return &(dbdata[0]), nil
}
// TouchRead updates the "last posted" date/time in the conference for the user.
func (c *Conference) TouchRead(u *User) (*ConferenceSettings, error) {
cs, err := c.Settings(u)
if err != nil {
return nil, err
}
if !u.IsAnon { // anon user can't update squat
if cs == nil {
ci, cerr := u.ContactInfo()
if cerr != nil {
return nil, cerr
}
amdb.Exec("INSERT INTO confsettings (confid, uid, default_pseud, last_read) VALUES (?, ?, ?, NOW())",
c.ConfId, u.Uid, ci.FullName(false))
} else {
_, err = amdb.Exec("UPDATE confsettings SET last_read = NOW() WHERE confid = ? AND uid = ?", c.ConfId, u.Uid)
}
if err == nil {
cs, err = c.Settings(u) // reread to get updated or inserted values
}
if err != nil {
return nil, err
}
}
return cs, nil
}
// TouchPost updates the "last posted" date/time in the conference for the user.
func (c *Conference) TouchPost(u *User, lastPost time.Time) (*ConferenceSettings, error) {
cs, err := c.Settings(u)
if err != nil {
return nil, err
}
if !u.IsAnon { // anon user can't update squat
if cs == nil {
ci, cerr := u.ContactInfo()
if cerr != nil {
return nil, cerr
}
defaultPseud := ci.FullName(false)
cs = &ConferenceSettings{
ConfId: c.ConfId,
Uid: u.Uid,
DefaultPseud: &defaultPseud,
LastRead: &lastPost,
LastPost: &lastPost,
}
_, err = amdb.Exec("INSERT INTO confsettings (confid, uid, default_pseud, last_read, last_post) VALUES (?, ?, ?, ?, ?)",
c.ConfId, u.Uid, defaultPseud, lastPost, lastPost)
} else {
_, err = amdb.Exec("UPDATE confsettings SET last_post = ? WHERE confid = ? AND uid = ?", lastPost, c.ConfId, u.Uid)
cs.LastPost = &lastPost
}
if err != nil {
return nil, err
}
}
return cs, nil
}
/* AmGetConference returns a conference given its ID.
* Parameters:
* id - The ID of the conference.
+6
View File
@@ -283,6 +283,12 @@ func AmNewTopic(conf *Conference, user *User, title string, zeroPostPseud string
amdb.Exec("UNLOCK TABLES;")
unlock = false
// update the "last posted" date in the conference settings
_, err = conf.TouchPost(user, topic.CreateDate)
if err != nil {
return nil, err
}
// create audit record
ar = AmNewAudit(AuditConferenceCreateTopic, user.Uid, ipaddr, fmt.Sprintf("confid=%d", conf.ConfId),
fmt.Sprintf("num=%d", topic.Number), fmt.Sprintf("name=%s", topic.Name))