fixed bug in AmNewPost and filling in default pseud for post box

This commit is contained in:
2026-01-05 23:05:52 -07:00
parent e581d7ded5
commit dd3a2ec677
4 changed files with 50 additions and 56 deletions
+32 -54
View File
@@ -137,19 +137,11 @@ func NewTopicForm(ctxt ui.AmContext) (string, any, error) {
ctxt.VarMap().Set("conferenceName", conf.Name) ctxt.VarMap().Set("conferenceName", conf.Name)
ctxt.VarMap().Set("urlStem", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.URLParam("confid"))) ctxt.VarMap().Set("urlStem", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.URLParam("confid")))
ctxt.VarMap().Set("topicName", "") ctxt.VarMap().Set("topicName", "")
cs, err := conf.Settings(ctxt.Ctx(), ctxt.CurrentUser()) pseud, err := conf.DefaultPseud(ctxt.Ctx(), ctxt.CurrentUser())
if err != nil { if err != nil {
return ui.ErrorPage(ctxt, err) return ui.ErrorPage(ctxt, err)
} }
if cs == nil || cs.DefaultPseud == nil { ctxt.VarMap().Set("pseud", pseud)
ci, err := ctxt.CurrentUser().ContactInfo(ctxt.Ctx())
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("pb", "")
ctxt.VarMap().Set("amsterdam_pageTitle", "Create New Topic") ctxt.VarMap().Set("amsterdam_pageTitle", "Create New Topic")
return "framed_template", "new_topic.jet", nil return "framed_template", "new_topic.jet", nil
@@ -524,6 +516,13 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) {
plc.LastPost = postRange[1] plc.LastPost = postRange[1]
postsPostRef := plc.AsString() postsPostRef := plc.AsString()
// Set the user's pseud.
pseud, err := conf.DefaultPseud(ctxt.Ctx(), ctxt.CurrentUser())
if err != nil {
return ui.ErrorPage(ctxt, err)
}
ctxt.VarMap().Set("pseud", pseud)
// Render the output. // Render the output.
ctxt.VarMap().Set("amsterdam_pageTitle", fmt.Sprintf("%s: %s", topic.Name, summaryLine)) ctxt.VarMap().Set("amsterdam_pageTitle", fmt.Sprintf("%s: %s", topic.Name, summaryLine))
ctxt.VarMap().Set("topicName", topic.Name) ctxt.VarMap().Set("topicName", topic.Name)
@@ -589,26 +588,29 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
return ui.ErrorPage(ctxt, errors.New("this topic is archived, and you do not have permission to post to it")) return ui.ErrorPage(ctxt, errors.New("this topic is archived, and you do not have permission to post to it"))
} }
// Set the escaped version of the text into the varmap, because it'll be needed if we do anything other than redirect.
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "escaper")
if err != nil {
return ui.ErrorPage(ctxt, err)
}
checker.Append(ctxt.FormField("pseud"))
checker.Finish()
v, _ := checker.Value()
ctxt.VarMap().Set("pseud", v)
postdata := ctxt.FormField("pb")
checker.Reset()
checker.Append(postdata)
checker.Finish()
v, _ = checker.Value()
ctxt.VarMap().Set("pb", v)
// also set the "attach" flag into the post data
if ctxt.FormFieldIsSet("attach") {
ctxt.VarMap().Set("attachFile", true)
}
if ctxt.FormFieldIsSet("preview") { if ctxt.FormFieldIsSet("preview") {
// Preview the post. // Preview the post.
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "escaper")
if err != nil {
return ui.ErrorPage(ctxt, err)
}
checker.Append(ctxt.FormField("pseud"))
checker.Finish()
v, _ := checker.Value()
ctxt.VarMap().Set("pseud", v)
// escape the data
postdata := ctxt.FormField("pb")
checker.Reset()
checker.Append(postdata)
checker.Finish()
v, _ = checker.Value()
ctxt.VarMap().Set("pb", v)
// run the preview
checker, err = htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "preview") checker, err = htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "preview")
if err != nil { if err != nil {
return ui.ErrorPage(ctxt, err) return ui.ErrorPage(ctxt, err)
@@ -622,9 +624,6 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
ctxt.VarMap().Set("nError", nErr) ctxt.VarMap().Set("nError", nErr)
ctxt.VarMap().Set("maxPost", ctxt.FormField("xp")) ctxt.VarMap().Set("maxPost", ctxt.FormField("xp"))
if ctxt.FormFieldIsSet("attach") {
ctxt.VarMap().Set("attachFile", true)
}
ctxt.VarMap().Set("urlStem", urlStem) ctxt.VarMap().Set("urlStem", urlStem)
ctxt.VarMap().Set("amsterdam_pageTitle", "Previewing Message") ctxt.VarMap().Set("amsterdam_pageTitle", "Previewing Message")
return "framed_template", "preview_post.jet", nil return "framed_template", "preview_post.jet", nil
@@ -652,27 +651,6 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
return ui.ErrorPage(ctxt, err) return ui.ErrorPage(ctxt, err)
} }
// start with escaping the post data
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "escaper")
if err != nil {
return ui.ErrorPage(ctxt, err)
}
checker.Append(ctxt.FormField("pseud"))
checker.Finish()
v, _ := checker.Value()
ctxt.VarMap().Set("pseud", v)
// escape the data
postdata := ctxt.FormField("pb")
checker.Reset()
checker.Append(postdata)
checker.Finish()
v, _ = checker.Value()
ctxt.VarMap().Set("pb", v)
if ctxt.FormFieldIsSet("attach") {
ctxt.VarMap().Set("attachFile", true)
}
plc := database.AmCreatePostLinkContext("", ctxt.GetScratch("currentAlias").(string), topic.Number) plc := database.AmCreatePostLinkContext("", ctxt.GetScratch("currentAlias").(string), topic.Number)
topicConferenceRef := plc.AsString() topicConferenceRef := plc.AsString()
plc.Community = comm.Alias plc.Community = comm.Alias
@@ -692,8 +670,8 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) {
return "framed_template", "slippage.jet", nil return "framed_template", "slippage.jet", nil
} }
// start by checking the title and pseud // if we get here, we are posting - start by checking the title and pseud
checker, err := htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "post-pseud") checker, err = htmlcheck.AmNewHTMLChecker(ctxt.Ctx(), "post-pseud")
if err != nil { if err != nil {
return ui.ErrorPage(ctxt, err) return ui.ErrorPage(ctxt, err)
} }
+16
View File
@@ -178,6 +178,22 @@ func (c *Conference) Settings(ctx context.Context, u *User) (*ConferenceSettings
return &(dbdata[0]), nil return &(dbdata[0]), nil
} }
// DefaultPseud returns the default pseud for a user in the conference.
func (c *Conference) DefaultPseud(ctx context.Context, u *User) (string, error) {
settings, err := c.Settings(ctx, u)
if err != nil {
return "", err
}
if settings != nil && settings.DefaultPseud != nil {
return *settings.DefaultPseud, nil
}
ci, err := u.ContactInfo(ctx)
if err != nil {
return "", err
}
return ci.FullName(false), nil
}
// TouchUpdate updates the "last update" date/time in the conference. // TouchUpdate updates the "last update" date/time in the conference.
func (c *Conference) TouchUpdate(ctx context.Context, tx *sqlx.Tx, lastUpdate time.Time) error { func (c *Conference) TouchUpdate(ctx context.Context, tx *sqlx.Tx, lastUpdate time.Time) error {
_, err := tx.ExecContext(ctx, "UPDATE confs SET lastupdate = ? WHERE confid = ?", lastUpdate, c.ConfId) _, err := tx.ExecContext(ctx, "UPDATE confs SET lastupdate = ? WHERE confid = ?", lastUpdate, c.ConfId)
+1 -1
View File
@@ -178,7 +178,7 @@ func AmNewPost(ctx context.Context, conf *Conference, topic *Topic, user *User,
hdr := &(dbdata[0]) hdr := &(dbdata[0])
// Add the post data. // Add the post data.
_, err = tx.ExecContext(ctx, "INSERT INTO postdata (postid, data) VALUES (?, ?)", int32(xid), hdr.PostId) _, err = tx.ExecContext(ctx, "INSERT INTO postdata (postid, data) VALUES (?, ?)", hdr.PostId, post)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+1 -1
View File
@@ -113,7 +113,7 @@
<div> <div>
<label for="pseud" class="block text-black text-sm font-medium mb-2">Your name/header:</label> <label for="pseud" class="block text-black text-sm font-medium mb-2">Your name/header:</label>
<div class="flex items-center gap-4"> <div class="flex items-center gap-4">
<input type="text" id="pseud" name="pseud" size="37" maxlength="255" value="System Administrator" <input type="text" id="pseud" name="pseud" size="37" maxlength="255" value="{{ pseud }}"
class="flex-1 px-3 py-2 border border-gray-300 rounded font-mono focus:outline-none focus:ring-2 focus:ring-blue-500"> class="flex-1 px-3 py-2 border border-gray-300 rounded font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<input type="checkbox" id="attach" name="attach" value="Y" class="w-4 h-4 text-blue-600 border-gray-300 rounded"> <input type="checkbox" id="attach" name="attach" value="Y" class="w-4 h-4 text-blue-600 border-gray-300 rounded">