set up show/hide of controls on topic page

This commit is contained in:
2026-01-15 22:59:27 -07:00
parent dd7b3d7858
commit d0c84216c3
4 changed files with 158 additions and 52 deletions
+40 -1
View File
@@ -457,6 +457,7 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) {
// Locate community, conference, and topic. // Locate community, conference, and topic.
comm := ctxt.CurrentCommunity() comm := ctxt.CurrentCommunity()
conf := ctxt.GetScratch("currentConference").(*database.Conference) conf := ctxt.GetScratch("currentConference").(*database.Conference)
myLevel := ctxt.GetScratch("levelInConference").(uint16)
var topic *database.Topic = nil var topic *database.Topic = nil
if rawTopic, err := strconv.ParseInt(ctxt.URLParam("topic"), 10, 16); err == nil { if rawTopic, err := strconv.ParseInt(ctxt.URLParam("topic"), 10, 16); err == nil {
topic, err = database.AmGetTopicByNumber(ctxt.Ctx(), conf, int16(rawTopic)) 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) 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. // 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("amsterdam_pageTitle", fmt.Sprintf("%s: %s", topic.Name, summaryLine))
ctxt.VarMap().Set("topicName", topic.Name) ctxt.VarMap().Set("topicName", topic.Name)
ctxt.VarMap().Set("summaryLine", summaryLine) ctxt.VarMap().Set("summaryLine", summaryLine)
+14
View File
@@ -44,6 +44,20 @@ func (p *PostHeader) IsScribbled() bool {
return p.ScribbleUid != nil && p.ScribbleDate != nil 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. /* SetAttachment sets the attachment data for a post.
* Parameters: * Parameters:
* ctx - Standard Go context value. * ctx - Standard Go context value.
+13
View File
@@ -81,6 +81,19 @@ func (t *Topic) SetLastRead(ctx context.Context, u *User, postNum int32) error {
return err 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. // TopicSettings contains per-user settings for topics, including the "last read" message pointer.
type TopicSettings struct { type TopicSettings struct {
TopicId int32 `db:"topicid"` // unique ID of the topic TopicId int32 `db:"topicid"` // unique ID of the topic
+56 -16
View File
@@ -20,22 +20,46 @@
<div class="flex gap-2 flex-wrap"> <div class="flex gap-2 flex-wrap">
<a href="{{ topicListLink }}" <a href="{{ topicListLink }}"
class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Topic List</a> class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Topic List</a>
<a href="/TODO/hide"
class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">
{{ if isTopicHidden }}Show Topic{{ else }}Hide Topic{{ end }}
</a>
{{ if false }}{* TODO *}
<a href="/TODO" <a href="/TODO"
class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Hide Topic</a> class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Next Topic</a>
{{ if false }}{* TODO *}
<a href="/TODO"
class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Next & Keep New</a>
{{ end }}
{{ end }}
<a href="/TODO" <a href="/TODO"
class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Find</a> class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Find</a>
<a href="/TODO" <a href="/TODO"
class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Manage</a> class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Manage</a>
</div> </div>
<div class="flex gap-2 flex-wrap"> <div class="flex gap-2 flex-wrap">
{{ if canStick }}
<a href="/TODO" <a href="/TODO"
class="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Stick Topic</a> class="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">
{{ if isSticky }}Unstick Topic{{ else }}Stick Topic{{ end }}
</a>
{{ end }}
{{ if canFreeze }}
<a href="/TODO" <a href="/TODO"
class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Freeze Topic</a> class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">
{{ if isFrozen }}Unfreeze Topic{{ else }}Freeze Topic{{ end }}
</a>
{{ end }}
{{ if canArchive }}
<a href="/TODO" <a href="/TODO"
class="bg-yellow-600 hover:bg-yellow-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Archive Topic</a> class="bg-yellow-600 hover:bg-yellow-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">
{{ if isArchived }}Unarchive Topic{{ else }}Archive Topic{{ end }}
</a>
{{ end }}
{{ if canDelete }}
<a href="/TODO" <a href="/TODO"
class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Delete Topic</a> class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Delete Topic</a>
{{ end }}
</div> </div>
</div> </div>
@@ -82,18 +106,32 @@
{{ .SubRender2("singlepost.jet", m) | raw }} {{ .SubRender2("singlepost.jet", m) | raw }}
{{ if advancedControls }} {{ if advancedControls }}
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<button class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap"> {{ if canHide }}
Hide <a href="/TODO"
</button> class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">
<button class="bg-yellow-600 hover:bg-yellow-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap"> {{ if isPostHidden }}Show{{ else }}Hide{{ end }}
Scribble </a>
</button> {{ end }}
<button class="bg-red-600 hover:bg-red-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap"> {{ if canScribble }}
Nuke <a href="/TODO"
</button> class="bg-yellow-600 hover:bg-yellow-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">Scribble</a>
<button class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap"> {{ end }}
Publish {{ if false }}{* TODO *}
</button> <a href="/TODO"
class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">Filter User</a>
{{ end }}
{{ if canNuke }}
<a href="/TODO"
class="bg-red-600 hover:bg-red-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">Nuke</a>
{{ end }}
{{ if false }}{* TODO *}
<a href="/TODO"
class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">Move</a>
{{ end }}
{{ if canPublish }}
<a href="/TODO"
class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">Publish</a>
{{ end }}
</div> </div>
{{ end }} {{ end }}
{{ if pin == p.Num }}<hr/>{{ end }} {{ if pin == p.Num }}<hr/>{{ end }}
@@ -121,6 +159,7 @@
</div> </div>
<!-- Reply Form --> <!-- Reply Form -->
{{ if canPost }}
<hr class="border-gray-400 mb-6"> <hr class="border-gray-400 mb-6">
<h2 class="text-2xl font-bold text-black mb-4">Post Message in "{{ topicName | raw }}":</h2> <h2 class="text-2xl font-bold text-black mb-4">Post Message in "{{ topicName | raw }}":</h2>
@@ -157,5 +196,6 @@
</div> </div>
</div> </div>
</form> </form>
{{ end }}
</div> </div>
</div> </div>