implemented topic hide/show
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+6
-4
@@ -20,10 +20,12 @@
|
||||
<div class="flex gap-2 flex-wrap">
|
||||
<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>
|
||||
<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 !.CurrentUser().IsAnon }}
|
||||
<a href="{{ topicListLink }}/op/{{ topicNum }}/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>
|
||||
{{ end }}
|
||||
{{ if isset(urlNextTopic) }}
|
||||
<a href="{{ urlNextTopic }}"
|
||||
class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded text-sm font-medium transition-colors">Next Topic</a>
|
||||
|
||||
Reference in New Issue
Block a user