From d0c84216c3fa1049d9750c12af8b4a8c31000514 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Thu, 15 Jan 2026 22:59:27 -0700 Subject: [PATCH] set up show/hide of controls on topic page --- conference.go | 41 ++++++++++++- database/post.go | 14 +++++ database/topic.go | 13 +++++ ui/views/posts.jet | 142 +++++++++++++++++++++++++++++---------------- 4 files changed, 158 insertions(+), 52 deletions(-) diff --git a/conference.go b/conference.go index a5b40d5..66a58fe 100644 --- a/conference.go +++ b/conference.go @@ -457,6 +457,7 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) { // Locate community, conference, and topic. comm := ctxt.CurrentCommunity() conf := ctxt.GetScratch("currentConference").(*database.Conference) + myLevel := ctxt.GetScratch("levelInConference").(uint16) var topic *database.Topic = nil if rawTopic, err := strconv.ParseInt(ctxt.URLParam("topic"), 10, 16); err == nil { topic, err = database.AmGetTopicByNumber(ctxt.Ctx(), conf, int16(rawTopic)) @@ -526,8 +527,46 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) { } ctxt.VarMap().Set("pseud", pseud) + // Set permission and status flags. + hidden, _ := topic.IsHidden(ctxt.Ctx(), ctxt.CurrentUser()) + ctxt.VarMap().Set("isTopicHidden", hidden) + confHidePerm := conf.TestPermission("Conference.Hide", myLevel) + ctxt.VarMap().Set("canFreeze", confHidePerm) + ctxt.VarMap().Set("canArchive", confHidePerm) + ctxt.VarMap().Set("canStick", confHidePerm) + ctxt.VarMap().Set("isFrozen", topic.Frozen) + ctxt.VarMap().Set("isArchived", topic.Archived) + ctxt.VarMap().Set("isSticky", topic.Sticky) + confNukePerm := conf.TestPermission("Conference.Nuke", myLevel) + ctxt.VarMap().Set("canDelete", confNukePerm) + ctxt.VarMap().Set("canPost", (!(topic.Frozen || topic.Archived) || confHidePerm) && conf.TestPermission("Conference.Post", myLevel)) + + // Set advanced controls. + advancedControls := ctxt.HasParameter("ac") && (len(posts) == 1) + if advancedControls { + isMyPost := (posts[0].CreatorUid == ctxt.CurrentUserId()) && !ctxt.CurrentUser().IsAnon + isScribbled := posts[0].IsScribbled() + canHide := !isScribbled && (isMyPost || confHidePerm) + ctxt.VarMap().Set("canHide", canHide) + ctxt.VarMap().Set("isPostHidden", posts[0].Hidden) + canScribble := !isScribbled && (isMyPost || confNukePerm) + ctxt.VarMap().Set("canScribble", canScribble) + ctxt.VarMap().Set("canNuke", confNukePerm) + canPublish := !isScribbled && database.AmTestPermission("Global.PublishFP", myLevel) + if canPublish { + published, _ := posts[0].IsPublished(ctxt.Ctx()) + if published { + canPublish = false + } + } + ctxt.VarMap().Set("canPublish", canPublish) + if !canHide && !canScribble && !confNukePerm && !canPublish { + advancedControls = false + } + } + ctxt.VarMap().Set("advancedControls", advancedControls) + // Render the output. - ctxt.VarMap().Set("advancedControls", ctxt.HasParameter("ac") && len(posts) == 1) ctxt.VarMap().Set("amsterdam_pageTitle", fmt.Sprintf("%s: %s", topic.Name, summaryLine)) ctxt.VarMap().Set("topicName", topic.Name) ctxt.VarMap().Set("summaryLine", summaryLine) diff --git a/database/post.go b/database/post.go index 1de6c99..74ff1c3 100644 --- a/database/post.go +++ b/database/post.go @@ -44,6 +44,20 @@ func (p *PostHeader) IsScribbled() bool { return p.ScribbleUid != nil && p.ScribbleDate != nil } +// IsPublished returns true if the post has been published to the front page. +func (p *PostHeader) IsPublished(ctx context.Context) (bool, error) { + rs, err := amdb.QueryContext(ctx, "SELECT COUNT(*) FROM postpublish WHERE postid = ?", p.PostId) + if err != nil { + return false, err + } + if !rs.Next() { + return false, errors.New("internal failure in IsPublished") + } + ct := 0 + err = rs.Scan(&ct) + return ct > 0, err +} + /* SetAttachment sets the attachment data for a post. * Parameters: * ctx - Standard Go context value. diff --git a/database/topic.go b/database/topic.go index 25ff2da..710a758 100644 --- a/database/topic.go +++ b/database/topic.go @@ -81,6 +81,19 @@ func (t *Topic) SetLastRead(ctx context.Context, u *User, postNum int32) error { return err } +// IsHidden tells us whether the user has the topic hidden. +func (t *Topic) IsHidden(ctx context.Context, u *User) (bool, error) { + rs, err := amdb.QueryContext(ctx, "SELECT hidden FROM topicsettings WHERE topicid = ? AND uid = ?", t.TopicId, u.Uid) + if err != nil { + return false, err + } + rc := false + if rs.Next() { + err = rs.Scan(&rc) + } + return rc, err +} + // TopicSettings contains per-user settings for topics, including the "last read" message pointer. type TopicSettings struct { TopicId int32 `db:"topicid"` // unique ID of the topic diff --git a/ui/views/posts.jet b/ui/views/posts.jet index 6c7a640..45f1bb9 100644 --- a/ui/views/posts.jet +++ b/ui/views/posts.jet @@ -20,22 +20,46 @@
Topic List - Hide Topic + + {{ if isTopicHidden }}Show Topic{{ else }}Hide Topic{{ end }} + + {{ if false }}{* TODO *} + Next Topic + {{ if false }}{* TODO *} + Next & Keep New + {{ end }} + {{ end }} Find Manage
- Stick Topic - Freeze Topic - Archive Topic - Delete Topic + {{ if canStick }} + + {{ if isSticky }}Unstick Topic{{ else }}Stick Topic{{ end }} + + {{ end }} + {{ if canFreeze }} + + {{ if isFrozen }}Unfreeze Topic{{ else }}Freeze Topic{{ end }} + + {{ end }} + {{ if canArchive }} + + {{ if isArchived }}Unarchive Topic{{ else }}Archive Topic{{ end }} + + {{ end }} + {{ if canDelete }} + Delete Topic + {{ end }}
@@ -82,18 +106,32 @@ {{ .SubRender2("singlepost.jet", m) | raw }} {{ if advancedControls }}
- - - - + {{ if canHide }} + + {{ if isPostHidden }}Show{{ else }}Hide{{ end }} + + {{ end }} + {{ if canScribble }} + Scribble + {{ end }} + {{ if false }}{* TODO *} + Filter User + {{ end }} + {{ if canNuke }} + Nuke + {{ end }} + {{ if false }}{* TODO *} + Move + {{ end }} + {{ if canPublish }} + Publish + {{ end }}
{{ end }} {{ if pin == p.Num }}
{{ end }} @@ -121,41 +159,43 @@ -
-

Post Message in "{{ topicName | raw }}":

- -
- + {{ if canPost }} +
+

Post Message in "{{ topicName | raw }}":

+ + + -
-
- -
- -
- - +
+
+ +
+ +
+ + +
-
-
-
- - HTML Guide +
+
+ + HTML Guide +
+
- -
-
- - - - +
+ + + + +
-
- + + {{ end }}