correct architectural goof where conference aliases had global scope instead of community scope (untested)

This commit is contained in:
2026-04-18 21:13:00 -05:00
parent 70dcf82234
commit 1348d0225f
11 changed files with 103 additions and 67 deletions
+7 -6
View File
@@ -247,7 +247,7 @@ func NewTopic(ctxt ui.AmContext) (string, any) {
if err != nil { if err != nil {
return "error", err return "error", err
} }
checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, ctxt.GetScratch("currentAlias").(string), conf.TopTopic+1)) checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, comm.Id, ctxt.GetScratch("currentAlias").(string), conf.TopTopic+1))
checker.Append(postdata) checker.Append(postdata)
checker.Finish() checker.Finish()
v, _ = checker.Value() v, _ = checker.Value()
@@ -282,7 +282,7 @@ func NewTopic(ctxt ui.AmContext) (string, any) {
if err != nil { if err != nil {
return "error", err return "error", err
} }
checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, ctxt.GetScratch("currentAlias").(string), conf.TopTopic+1)) checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, comm.Id, ctxt.GetScratch("currentAlias").(string), conf.TopTopic+1))
checker.Append(ctxt.FormField("pb")) checker.Append(ctxt.FormField("pb"))
checker.Finish() checker.Finish()
zeroPost, _ := checker.Value() zeroPost, _ := checker.Value()
@@ -560,7 +560,7 @@ func ReadPosts(ctxt ui.AmContext) (string, any) {
summaryLine := fmt.Sprintf("%d Total; %d New; Last: %s", topic.TopMessage+1, topic.TopMessage-lastRead, prefs.Localizer().Strftime("%b %e, %Y %r", topic.LastUpdate)) summaryLine := fmt.Sprintf("%d Total; %d New; Last: %s", topic.TopMessage+1, topic.TopMessage-lastRead, prefs.Localizer().Strftime("%b %e, %Y %r", topic.LastUpdate))
ctxt.VarMap().Set("summaryLine", flags.String()+summaryLine) ctxt.VarMap().Set("summaryLine", flags.String()+summaryLine)
ctxt.SetFrameTitle(fmt.Sprintf("%s: %s%s", topic.Name, flags.String(), summaryLine)) ctxt.SetFrameTitle(fmt.Sprintf("%s: %s%s", topic.Name, flags.String(), summaryLine))
plc := database.AmCreatePostLinkContext("", ctxt.GetScratch("currentAlias").(string), topic.Number) plc := database.AmCreatePostLinkContext("", comm.Id, ctxt.GetScratch("currentAlias").(string), topic.Number)
ctxt.VarMap().Set("post_confRef", plc.AsString()) ctxt.VarMap().Set("post_confRef", plc.AsString())
plc.Community = comm.Alias plc.Community = comm.Alias
ctxt.VarMap().Set("post_topicPermalink", fmt.Sprintf("/go/%s", plc.AsString())) ctxt.VarMap().Set("post_topicPermalink", fmt.Sprintf("/go/%s", plc.AsString()))
@@ -734,7 +734,7 @@ func PostInTopic(ctxt ui.AmContext) (string, any) {
if err != nil { if err != nil {
return "error", err return "error", err
} }
checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, ctxt.GetScratch("currentAlias").(string), topic.Number)) checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, comm.Id, ctxt.GetScratch("currentAlias").(string), topic.Number))
checker.Append(postdata) checker.Append(postdata)
checker.Finish() checker.Finish()
v, _ = checker.Value() v, _ = checker.Value()
@@ -772,7 +772,7 @@ func PostInTopic(ctxt ui.AmContext) (string, any) {
return "error", err return "error", err
} }
plc := database.AmCreatePostLinkContext("", ctxt.GetScratch("currentAlias").(string), topic.Number) plc := database.AmCreatePostLinkContext("", comm.Id, ctxt.GetScratch("currentAlias").(string), topic.Number)
ctxt.VarMap().Set("post_confRef", plc.AsString()) ctxt.VarMap().Set("post_confRef", plc.AsString())
plc.Community = comm.Alias plc.Community = comm.Alias
ctxt.VarMap().Set("post_topicPermalink", fmt.Sprintf("/go/%s", plc.AsString())) ctxt.VarMap().Set("post_topicPermalink", fmt.Sprintf("/go/%s", plc.AsString()))
@@ -805,7 +805,8 @@ func PostInTopic(ctxt ui.AmContext) (string, any) {
if err != nil { if err != nil {
return "error", err return "error", err
} }
checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, ctxt.GetScratch("currentAlias").(string), topic.Number)) checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, comm.Id,
ctxt.GetScratch("currentAlias").(string), topic.Number))
checker.Append(ctxt.FormField("pb")) checker.Append(ctxt.FormField("pb"))
checker.Finish() checker.Finish()
postText, _ := checker.Value() postText, _ := checker.Value()
+2 -2
View File
@@ -470,7 +470,7 @@ func NukeMessage(ctxt ui.AmContext) (string, any) {
} }
// Set up to display the message box. // Set up to display the message box.
link, err := hdrs[0].Link(ctxt.Ctx(), "community") link, err := hdrs[0].Link(ctxt.Ctx(), ctxt.CurrentCommunity().Id, "community")
if err != nil { if err != nil {
return "error", err return "error", err
} }
@@ -528,7 +528,7 @@ func PruneMessageAttachment(ctxt ui.AmContext) (string, any) {
} }
// Set up to display the message box. // Set up to display the message box.
link, err := hdrs[0].Link(ctxt.Ctx(), "community") link, err := hdrs[0].Link(ctxt.Ctx(), ctxt.CurrentCommunity().Id, "community")
if err != nil { if err != nil {
return "error", err return "error", err
} }
+2 -2
View File
@@ -159,7 +159,7 @@ func ConferenceAliasForm(ctxt ui.AmContext) (string, any) {
} }
} }
aliases, err := conf.Aliases(ctxt.Ctx()) aliases, err := conf.Aliases(ctxt.Ctx(), comm.Id)
if err != nil { if err != nil {
return "error", err return "error", err
} }
@@ -206,7 +206,7 @@ func ConferenceAliasAdd(ctxt ui.AmContext) (string, any) {
ctxt.VarMap().Set("errorMessage", err.Error()) ctxt.VarMap().Set("errorMessage", err.Error())
} }
aliases, err := conf.Aliases(ctxt.Ctx()) aliases, err := conf.Aliases(ctxt.Ctx(), comm.Id)
if err != nil { if err != nil {
return "error", err return "error", err
} }
+28 -30
View File
@@ -152,8 +152,8 @@ func (cs *ConferenceSettings) Save(ctx context.Context) error {
} }
// Aliases returns the list of aliases for this conference. // Aliases returns the list of aliases for this conference.
func (c *Conference) Aliases(ctx context.Context) ([]string, error) { func (c *Conference) Aliases(ctx context.Context, commid int32) ([]string, error) {
rs, err := amdb.QueryContext(ctx, "SELECT alias FROM confalias WHERE confid = ? ORDER BY alias", c.ConfId) rs, err := amdb.QueryContext(ctx, "SELECT alias FROM confalias WHERE commid = ? AND confid = ? ORDER BY alias", commid, c.ConfId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -169,22 +169,18 @@ func (c *Conference) Aliases(ctx context.Context) ([]string, error) {
return rc, nil return rc, nil
} }
// AliasesQ returns the list of aliases for this conference, quietly.
func (c *Conference) AliasesQ(ctx context.Context) []string {
rc, _ := c.Aliases(ctx)
return rc
}
// AddAlias adds an alias to the conference. // AddAlias adds an alias to the conference.
func (c *Conference) AddAlias(ctx context.Context, alias string, u *User, comm *Community, ipaddr string) error { func (c *Conference) AddAlias(ctx context.Context, alias string, u *User, comm *Community, ipaddr string) error {
tmp := "" tmp := ""
if err := amdb.GetContext(ctx, &tmp, "SELECT alias FROM confalias WHERE confid = ? AND alias = ?", c.ConfId, alias); err != sql.ErrNoRows { if err := amdb.GetContext(ctx, &tmp, "SELECT alias FROM confalias WHERE commid = ? AND confid = ? AND alias = ?",
comm.Id, c.ConfId, alias); err != sql.ErrNoRows {
if err == nil { if err == nil {
return fmt.Errorf("the alias '%s' is already in use by another conference", alias) return fmt.Errorf("the alias '%s' is already in use by another conference", alias)
} }
return err return err
} }
if _, err := amdb.ExecContext(ctx, "INSERT INTO confalias (confid, alias) VALUES (?, ?)", c.ConfId, alias); err != nil { if _, err := amdb.ExecContext(ctx, "INSERT INTO confalias (commid, confid, alias) VALUES (?, ?)",
comm.Id, c.ConfId, alias); err != nil {
return err return err
} }
@@ -195,13 +191,15 @@ func (c *Conference) AddAlias(ctx context.Context, alias string, u *User, comm *
// RemoveAlias removes an alias from the conference. // RemoveAlias removes an alias from the conference.
func (c *Conference) RemoveAlias(ctx context.Context, alias string, u *User, comm *Community, ipaddr string) error { func (c *Conference) RemoveAlias(ctx context.Context, alias string, u *User, comm *Community, ipaddr string) error {
aliasCount := 0 aliasCount := 0
if err := amdb.GetContext(ctx, &aliasCount, "SELECT COUNT(*) FROM confalias WHERE confid = ?", c.ConfId); err != nil { if err := amdb.GetContext(ctx, &aliasCount, "SELECT COUNT(*) FROM confalias WHERE commid = ? AND confid = ?",
comm.Id, c.ConfId); err != nil {
return err return err
} }
if aliasCount == 1 { if aliasCount == 1 {
tmp := "" tmp := ""
err := amdb.GetContext(ctx, &tmp, "SELECT alias FROM confalias WHERE confid = ? AND alias = ?", c.ConfId, alias) err := amdb.GetContext(ctx, &tmp, "SELECT alias FROM confalias WHERE commid = ? AND confid = ? AND alias = ?",
comm.Id, c.ConfId, alias)
if err == nil { if err == nil {
return errors.New("the conference must have at least one alias") return errors.New("the conference must have at least one alias")
} else if err != sql.ErrNoRows { } else if err != sql.ErrNoRows {
@@ -209,7 +207,7 @@ func (c *Conference) RemoveAlias(ctx context.Context, alias string, u *User, com
} }
} }
rs, err := amdb.ExecContext(ctx, "DELETE FROM confalias WHERE confid = ? AND alias = ?", c.ConfId, alias) rs, err := amdb.ExecContext(ctx, "DELETE FROM confalias WHERE commid = ? confid = ? AND alias = ?", comm.Id, c.ConfId, alias)
if err != nil { if err != nil {
return err return err
} }
@@ -431,8 +429,8 @@ func (c *Conference) Settings(ctx context.Context, u *User) (*ConferenceSettings
} }
// Link returns a link string to this conference. // Link returns a link string to this conference.
func (c *Conference) Link(ctx context.Context, scope string) (string, error) { func (c *Conference) Link(ctx context.Context, commid int32, scope string) (string, error) {
aliases, err := c.Aliases(ctx) aliases, err := c.Aliases(ctx, commid)
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -440,9 +438,9 @@ func (c *Conference) Link(ctx context.Context, scope string) (string, error) {
return fmt.Sprintf("%s.", aliases[0]), nil return fmt.Sprintf("%s.", aliases[0]), nil
} }
if scope == "global" { if scope == "global" {
comms, err := c.ContainedBy(ctx) comm, err := AmGetCommunity(ctx, commid)
if err == nil { if err == nil {
return fmt.Sprintf("%s!%s", comms[0].Alias, aliases[0]), nil return fmt.Sprintf("%s!%s", comm.Alias, aliases[0]), nil
} }
return "", err return "", err
} }
@@ -872,22 +870,22 @@ func (c *Conference) Delete(ctx context.Context, comm *Community, u *User, ipadd
// any references to conference other than this community? // any references to conference other than this community?
refCount := 0 refCount := 0
if err := tx.GetContext(ctx, &refCount, "SELECT COUNT(*) FROM commtoconf WHERE confid = ? AND commid <> ?", c.ConfId, comm.Id); err != nil { err := tx.GetContext(ctx, &refCount, "SELECT COUNT(*) FROM commtoconf WHERE confid = ? AND commid <> ?", c.ConfId, comm.Id)
if err != nil {
return err return err
} }
// break the link with the community // break the link with the community
if _, err := tx.ExecContext(ctx, "DELETE FROM commtoconf WHERE commid = ? AND confid = ?", comm.Id, c.ConfId); err != nil { if _, err = tx.ExecContext(ctx, "DELETE FROM commtoconf WHERE commid = ? AND confid = ?", comm.Id, c.ConfId); err == nil {
_, err = tx.ExecContext(ctx, "DELETE FROM confalias WHERE commid = ? AND confid = ?", comm.Id, c.ConfId)
}
if err != nil {
return err return err
} }
var err error
if refCount == 0 { if refCount == 0 {
// We have to delete all the conference core data now. // We have to delete all the conference core data now.
_, err = tx.ExecContext(ctx, "DELETE FROM confs WHERE confid = ?", c.ConfId) _, err = tx.ExecContext(ctx, "DELETE FROM confs WHERE confid = ?", c.ConfId)
if err == nil {
_, err = tx.ExecContext(ctx, "DELETE FROM confalias WHERE confid = ?", c.ConfId)
}
} }
if err != nil { if err != nil {
return err return err
@@ -1038,13 +1036,13 @@ func AmGetConference(ctx context.Context, id int32) (*Conference, error) {
* Pointer to the conference, or nil. * Pointer to the conference, or nil.
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetConferenceByAlias(ctx context.Context, alias string) (*Conference, error) { func AmGetConferenceByAlias(ctx context.Context, commid int32, alias string) (*Conference, error) {
var confid int32 var confid int32
xconf, ok := conferenceAliasMap.Load(alias) xconf, ok := conferenceAliasMap.Load(alias)
if ok { if ok {
confid = xconf.(int32) confid = xconf.(int32)
} else { } else {
err := amdb.GetContext(ctx, &confid, "SELECT confid FROM confalias WHERE alias = ?", alias) err := amdb.GetContext(ctx, &confid, "SELECT confid FROM confalias WHERE commid = ? AND alias = ?", commid, alias)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return nil, fmt.Errorf("alias not found: %s", alias) return nil, fmt.Errorf("alias not found: %s", alias)
} else if err != nil { } else if err != nil {
@@ -1085,8 +1083,7 @@ func AmGetConferenceContainingPost(ctx context.Context, postId int64) (*Conferen
*/ */
func AmGetConferenceByAliasInCommunity(ctx context.Context, cid int32, alias string) (*Conference, error) { func AmGetConferenceByAliasInCommunity(ctx context.Context, cid int32, alias string) (*Conference, error) {
var confid int32 var confid int32
err := amdb.GetContext(ctx, &confid, `SELECT c.confid FROM commtoconf c, confalias a WHERE c.confid = a.confid err := amdb.GetContext(ctx, &confid, `SELECT confid FROM confalias WHERE commid = ? AND alias = ?`, cid, alias)
AND c.commid = ? AND a.alias = ?`, cid, alias)
switch err { switch err {
case nil: case nil:
return AmGetConference(ctx, confid) return AmGetConference(ctx, confid)
@@ -1125,7 +1122,7 @@ func AmListConferences(ctx context.Context, cid int32, showHidden bool) ([]*Conf
} }
} }
for i := range rc { for i := range rc {
err := amdb.GetContext(ctx, &(rc[i].Alias), "SELECT alias FROM confalias WHERE confid = ?", rc[i].ConfId) err := amdb.GetContext(ctx, &(rc[i].Alias), "SELECT alias FROM confalias WHERE commid = ? AND confid = ?", cid, rc[i].ConfId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1271,7 +1268,7 @@ func AmCreateConference(ctx context.Context, comm *Community, name, alias, descr
// Ensure the alias is not in use. // Ensure the alias is not in use.
var tmp int32 var tmp int32
err := tx.GetContext(ctx, &tmp, "SELECT confid FROM confalias WHERE alias = ?", alias) err := tx.GetContext(ctx, &tmp, "SELECT confid FROM confalias WHERE commid = ? AND alias = ?", comm.Id, alias)
if err == nil { if err == nil {
return nil, fmt.Errorf("the alias '%s' is already in use by a different conference", alias) return nil, fmt.Errorf("the alias '%s' is already in use by a different conference", alias)
} else if err != sql.ErrNoRows { } else if err != sql.ErrNoRows {
@@ -1295,7 +1292,8 @@ func AmCreateConference(ctx context.Context, comm *Community, name, alias, descr
} }
// Attach the alias to the conference. // Attach the alias to the conference.
if _, err = tx.ExecContext(ctx, "INSERT INTO confalias (confid, alias) VALUES (?, ?)", rc.ConfId, alias); err != nil { if _, err = tx.ExecContext(ctx, "INSERT INTO confalias (commid, confid, alias) VALUES (?, ?, ?)",
comm.Id, rc.ConfId, alias); err != nil {
return nil, err return nil, err
} }
+23
View File
@@ -0,0 +1,23 @@
# Amsterdam Web Communities System
# 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
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
CREATE TABLE newconfalias (
commid INT NOT NULL,
confid INT NOT NULL,
alias VARCHAR(64) NOT NULL,
PRIMARY KEY (commid, alias),
INDEX confid_x (commid, confid)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
INSERT INTO newconfalias (commid, confid, alias)
SELECT c.commid, c.confid, a.alias FROM commtoconf c, confalias a
WHERE c.confid = a.confid;
DROP TABLE confalias;
ALTER TABLE newconfalias RENAME TO confalias;
+24 -16
View File
@@ -253,7 +253,7 @@ func (p *PostHeader) Text(ctx context.Context) (string, error) {
} }
// Link returns a link string to this post. // Link returns a link string to this post.
func (p *PostHeader) Link(ctx context.Context, scope string) (string, error) { func (p *PostHeader) Link(ctx context.Context, commid int32, scope string) (string, error) {
if scope == "topic" { if scope == "topic" {
return fmt.Sprintf("%d", p.Num), nil return fmt.Sprintf("%d", p.Num), nil
} }
@@ -262,7 +262,7 @@ func (p *PostHeader) Link(ctx context.Context, scope string) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
parent, err := topic.Link(ctx, scope) parent, err := topic.Link(ctx, commid, scope)
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -628,47 +628,55 @@ func AmNewPost(ctx context.Context, conf *Conference, topic *Topic, user *User,
* Array of post headers, or nil. * Array of post headers, or nil.
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetPublishedPosts(ctx context.Context) ([]*PostHeader, error) { func AmGetPublishedPosts(ctx context.Context) ([]*PostHeader, []*Community, error) {
// Read the globals. // Read the globals.
gv, err := AmGlobals(ctx) gv, err := AmGlobals(ctx)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
// Read the published posts. // Read the published posts.
rs, err := amdb.QueryContext(ctx, "SELECT postid FROM postpublish ORDER BY on_date DESC") rs, err := amdb.QueryContext(ctx, "SELECT commid, postid FROM postpublish ORDER BY on_date DESC")
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
// Extract post IDs to an array. // Extract post IDs to an array.
cids := make([]int32, gv.FrontPagePosts)
pids := make([]int64, gv.FrontPagePosts) pids := make([]int64, gv.FrontPagePosts)
i := 0 i := 0
for i < int(gv.FrontPagePosts) && rs.Next() { for i < int(gv.FrontPagePosts) && rs.Next() {
if err = rs.Scan(&(pids[i])); err != nil { if err = rs.Scan(&(cids[i]), &(pids[i])); err != nil {
return nil, err return nil, nil, err
} }
i++ i++
} }
if i == 0 { // no published posts, short-circuit response if i == 0 { // no published posts, short-circuit response
return make([]*PostHeader, 0), nil return make([]*PostHeader, 0), make([]*Community, 0), nil
} }
if i < int(gv.FrontPagePosts) { if i < int(gv.FrontPagePosts) {
cids = cids[:i]
pids = pids[:i] // truncate if we have fewer posts than spaces pids = pids[:i] // truncate if we have fewer posts than spaces
} }
// Build the communities return array.
comms := make([]*Community, len(cids))
for i, cid := range cids {
comms[i], _ = AmGetCommunity(ctx, cid)
}
// Use the post IDs to build a SQL statement. // Use the post IDs to build a SQL statement.
query, args, err := sqlx.In("SELECT * FROM posts WHERE postid IN (?)", pids) query, args, err := sqlx.In("SELECT * FROM posts WHERE postid IN (?)", pids)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
query = amdb.Rebind(query) query = amdb.Rebind(query)
// Use the SQL to read in all the post headers using a single database query. // Use the SQL to read in all the post headers using a single database query.
var data []PostHeader var data []PostHeader
if err = amdb.SelectContext(ctx, &data, query, args...); err != nil { if err = amdb.SelectContext(ctx, &data, query, args...); err != nil {
return nil, err return nil, nil, err
} }
if len(data) < len(pids) { if len(data) < len(pids) {
return nil, errors.New("internal error reading post headers") return nil, nil, errors.New("internal error reading post headers")
} }
// Build the return array by making sure we point to the post headers in the same order the post IDs were returned. // Build the return array by making sure we point to the post headers in the same order the post IDs were returned.
@@ -683,10 +691,10 @@ func AmGetPublishedPosts(ctx context.Context) ([]*PostHeader, error) {
} }
} }
if q < len(pids) { if q < len(pids) {
return nil, errors.New("internal error generating output") return nil, nil, errors.New("internal error generating output")
} }
return rc, nil return rc, comms, nil
} }
type PostSearchResult struct { type PostSearchResult struct {
@@ -898,13 +906,13 @@ func AmSearchPosts(ctx context.Context, searchTerms string, u *User, offset, max
if err != nil { if err != nil {
return nil, count, err return nil, count, err
} }
alias, err := conf.Aliases(ctx) alias, err := conf.Aliases(ctx, commid)
if err != nil { if err != nil {
return nil, count, err return nil, count, err
} }
// Build the post link. // Build the post link.
plink := AmCreatePostLinkContext(commAlias, alias[0], topicNum) plink := AmCreatePostLinkContext(commAlias, commid, alias[0], topicNum)
plink.FirstPost = postnum plink.FirstPost = postnum
plink.LastPost = postnum plink.LastPost = postnum
rc[i].PostLink = plink.AsString() rc[i].PostLink = plink.AsString()
+6 -2
View File
@@ -23,6 +23,7 @@ import (
// PostLinkData is the structure holding the decoded parts of the post link. // PostLinkData is the structure holding the decoded parts of the post link.
type PostLinkData struct { type PostLinkData struct {
Community string Community string
CommId int32
Conference string Conference string
Topic int16 Topic int16
FirstPost int32 FirstPost int32
@@ -36,6 +37,7 @@ func (d *PostLinkData) NeedsDBVerification() bool {
// VerifyNames verifies the post link data against the database. // VerifyNames verifies the post link data against the database.
func (d *PostLinkData) VerifyNames(ctx context.Context) error { func (d *PostLinkData) VerifyNames(ctx context.Context) error {
commid := d.CommId
if d.Community != "" { if d.Community != "" {
comm, err := AmGetCommunityByAlias(ctx, d.Community) comm, err := AmGetCommunityByAlias(ctx, d.Community)
if err != nil { if err != nil {
@@ -44,9 +46,10 @@ func (d *PostLinkData) VerifyNames(ctx context.Context) error {
if comm == nil { if comm == nil {
return errors.New("community alias not found") return errors.New("community alias not found")
} }
commid = comm.Id
} }
if d.Conference != "" { if d.Conference != "" {
conf, err := AmGetConferenceByAlias(ctx, d.Conference) conf, err := AmGetConferenceByAlias(ctx, commid, d.Conference)
if err != nil { if err != nil {
return err return err
} }
@@ -392,9 +395,10 @@ func AmDecodePostLink(data string) (*PostLinkData, error) {
return &rc, nil return &rc, nil
} }
func AmCreatePostLinkContext(community string, conference string, topic int16) *PostLinkData { func AmCreatePostLinkContext(community string, commid int32, conference string, topic int16) *PostLinkData {
return &PostLinkData{ return &PostLinkData{
Community: community, Community: community,
CommId: commid,
Conference: conference, Conference: conference,
Topic: topic, Topic: topic,
FirstPost: -1, FirstPost: -1,
+2 -2
View File
@@ -43,7 +43,7 @@ type Topic struct {
} }
// Link returns a link string to this topic. // Link returns a link string to this topic.
func (t *Topic) Link(ctx context.Context, scope string) (string, error) { func (t *Topic) Link(ctx context.Context, commid int32, scope string) (string, error) {
if scope == "conference" { if scope == "conference" {
return fmt.Sprintf("%d.", t.Number), nil return fmt.Sprintf("%d.", t.Number), nil
} }
@@ -51,7 +51,7 @@ func (t *Topic) Link(ctx context.Context, scope string) (string, error) {
conf, err := AmGetConference(ctx, t.ConfId) conf, err := AmGetConference(ctx, t.ConfId)
if err == nil { if err == nil {
var plink string var plink string
plink, err = conf.Link(ctx, scope) plink, err = conf.Link(ctx, commid, scope)
if err == nil { if err == nil {
if strings.HasSuffix(plink, ".") { if strings.HasSuffix(plink, ".") {
return fmt.Sprintf("%s%d", plink, t.Number), nil return fmt.Sprintf("%s%d", plink, t.Number), nil
+1 -1
View File
@@ -88,7 +88,7 @@ func AmDeliverSubscription(ctx context.Context, comm *database.Community, conf *
vars.Set("communityName", comm.Name) vars.Set("communityName", comm.Name)
vars.Set("conferenceName", conf.Name) vars.Set("conferenceName", conf.Name)
vars.Set("topicName", topic.Name) vars.Set("topicName", topic.Name)
pl := database.AmCreatePostLinkContext(comm.Alias, confAlias, topic.Number) pl := database.AmCreatePostLinkContext(comm.Alias, comm.Id, confAlias, topic.Number)
vars.Set("topicLink", pl.AsString()) vars.Set("topicLink", pl.AsString())
vars.Set("pseud", realPseud) vars.Set("pseud", realPseud)
vars.Set("text", realText) vars.Set("text", realText)
+7 -5
View File
@@ -93,7 +93,7 @@ func renderSBConferences(ctx context.Context, u *database.User, sb *DisplaySideb
return err return err
} }
var a []string var a []string
if a, err = conf[i].Aliases(ctx); err != nil { if a, err = conf[i].Aliases(ctx, comm[i].Id); err != nil {
return err return err
} }
alias[i] = a[0] alias[i] = a[0]
@@ -176,9 +176,10 @@ func templateGetTopic(args jet.Arguments) reflect.Value {
// templateTopicLink returns the link string for the given topic. // templateTopicLink returns the link string for the given topic.
func templateTopicLink(args jet.Arguments) reflect.Value { func templateTopicLink(args jet.Arguments) reflect.Value {
topic := args.Get(0).Convert(reflect.TypeFor[*database.Topic]()).Interface().(*database.Topic) comm := args.Get(0).Convert(reflect.TypeFor[*database.Community]()).Interface().(*database.Community)
ctxt := args.Get(1).Convert(reflect.TypeFor[ui.AmContext]()).Interface().(ui.AmContext) topic := args.Get(1).Convert(reflect.TypeFor[*database.Topic]()).Interface().(*database.Topic)
link, _ := topic.Link(ctxt.Ctx(), "global") ctxt := args.Get(2).Convert(reflect.TypeFor[ui.AmContext]()).Interface().(ui.AmContext)
link, _ := topic.Link(ctxt.Ctx(), comm.Id, "global")
return reflect.ValueOf(link) return reflect.ValueOf(link)
} }
@@ -194,12 +195,13 @@ func TopPage(ctxt ui.AmContext) (string, any) {
ctxt.SetFrameTitle("My Front Page") ctxt.SetFrameTitle("My Front Page")
// Retrieve the published posts. // Retrieve the published posts.
hdrs, err := database.AmGetPublishedPosts(ctxt.Ctx()) hdrs, comms, err := database.AmGetPublishedPosts(ctxt.Ctx())
if err != nil { if err != nil {
return "error", err return "error", err
} }
ctxt.VarMap().Set("posts", hdrs) ctxt.VarMap().Set("posts", hdrs)
ctxt.VarMap().Set("comms", comms)
ctxt.VarMap().SetFunc("post_getText", templatePostText) ctxt.VarMap().SetFunc("post_getText", templatePostText)
ctxt.VarMap().SetFunc("post_getUserName", templateExtractUserName) ctxt.VarMap().SetFunc("post_getUserName", templateExtractUserName)
ctxt.VarMap().SetFunc("post_topic", templateGetTopic) ctxt.VarMap().SetFunc("post_topic", templateGetTopic)
+1 -1
View File
@@ -33,7 +33,7 @@
{{ user = post_getUserName(p, .) }} {{ user = post_getUserName(p, .) }}
{{ text = post_getText(p, .) }} {{ text = post_getText(p, .) }}
{{ topic = post_topic(p, .) }} {{ topic = post_topic(p, .) }}
{{ link = post_topicLink(topic, .) }} {{ link = post_topicLink(topic, comms[i], .) }}
<div class="text-black text-sm"> <div class="text-black text-sm">
<div class="mb-2"> <div class="mb-2">
<strong>{{ p.Pseud | raw }}</strong> <strong>{{ p.Pseud | raw }}</strong>