diff --git a/conference_ops.go b/conference_ops.go new file mode 100644 index 0000000..708521d --- /dev/null +++ b/conference_ops.go @@ -0,0 +1,39 @@ +/* + * 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/. + */ + +// Package main contains the high-level Amsterdam logic. +package main + +import ( + "fmt" + + "git.erbosoft.com/amy/amsterdam/database" + "git.erbosoft.com/amy/amsterdam/ui" +) + +/* HideTopic hides or shows rthe current topic for the current user. + * Parameters: + * ctxt - The AmContext for the request. + * Returns: + * Command string dictating what to be rendered. + * Data as a parameter for the command string. + * Standard Go error status. + */ +func HideTopic(ctxt ui.AmContext) (string, any, error) { + topic := ctxt.GetScratch("currentTopic").(*database.Topic) + hidden, err := topic.IsHidden(ctxt.Ctx(), ctxt.CurrentUser()) + if err != nil { + return ui.ErrorPage(ctxt, err) + } + err = topic.SetHidden(ctxt.Ctx(), ctxt.CurrentUser(), !hidden) + if err != nil { + return ui.ErrorPage(ctxt, err) + } + return "redirect", fmt.Sprintf("/comm/%s/conf/%s/r/%d", ctxt.CurrentCommunity().Alias, ctxt.GetScratch("currentAlias"), topic.Number), nil +} diff --git a/database/topic.go b/database/topic.go index 710a758..bc49df9 100644 --- a/database/topic.go +++ b/database/topic.go @@ -94,6 +94,18 @@ func (t *Topic) IsHidden(ctx context.Context, u *User) (bool, error) { return rc, err } +// SetHidden sets the "hidden" state on a topic for a user. +func (t *Topic) SetHidden(ctx context.Context, u *User, hidden bool) error { + rs, err := amdb.ExecContext(ctx, "UPDATE topicsettings SET hidden = ? WHERE topicid = ? AND uid = ?", hidden, t.TopicId, u.Uid) + if err == nil { + nrow, _ := rs.RowsAffected() + if nrow == 0 { + _, err = amdb.ExecContext(ctx, "INSERT INTO topicsettings (topicid, uid, hidden) VALUES (?, ?, ?)", t.TopicId, u.Uid, hidden) + } + } + return 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/main.go b/main.go index 0a7c056..267b36a 100644 --- a/main.go +++ b/main.go @@ -99,6 +99,8 @@ func setupEcho() *echo.Echo { confGroup.POST("/new_topic", ui.AmWrap(NewTopic)) confGroup.GET("/r/:topic", ui.AmWrap(ReadPosts), ui.SetTopic) confGroup.POST("/r/:topic", ui.AmWrap(PostInTopic), ui.SetTopic) + opsGroup := confGroup.Group("/op/:topic", ui.SetTopic) + opsGroup.GET("/hide", ui.AmWrap(HideTopic)) return e } diff --git a/ui/views/posts.jet b/ui/views/posts.jet index dc2825b..90a04f0 100644 --- a/ui/views/posts.jet +++ b/ui/views/posts.jet @@ -20,10 +20,12 @@
Topic List - - {{ if isTopicHidden }}Show Topic{{ else }}Hide Topic{{ end }} - + {{ if !.CurrentUser().IsAnon }} + + {{ if isTopicHidden }}Show Topic{{ else }}Hide Topic{{ end }} + + {{ end }} {{ if isset(urlNextTopic) }} Next Topic