added topic subscribe/unsubscribe

This commit is contained in:
2026-01-29 16:12:27 -07:00
parent 184c614163
commit 8a66579c31
5 changed files with 66 additions and 4 deletions
+33 -2
View File
@@ -429,6 +429,13 @@ func TopicManage(ctxt ui.AmContext) (string, any, error) {
}
ctxt.VarMap().Set("canInvite", member)
// Get the E-mail subscription status.
sub, err := topic.IsSubscribed(ctxt.Ctx(), ctxt.CurrentUser())
if err != nil {
return ui.ErrorPage(ctxt, err)
}
ctxt.VarMap().Set("subscribed", sub)
// Get the filtered users list.
bozos, err := topic.GetBozos(ctxt.Ctx(), ctxt.CurrentUser())
if err != nil {
@@ -436,12 +443,36 @@ func TopicManage(ctxt ui.AmContext) (string, any, error) {
}
ctxt.VarMap().Set("bozos", bozos)
ctxt.VarMap().Set("subscribed", false) // TODO
ctxt.VarMap().Set("amsterdam_pageTitle", "Manage Topic: "+topic.Name)
return "framed_template", "manage_topic.jet", nil
}
/* TopicSetSubscribe toggles the "subscription" flag on the 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 TopicSetSubscribe(ctxt ui.AmContext) (string, any, error) {
if ctxt.CurrentUser().IsAnon {
ctxt.SetRC(http.StatusForbidden)
return ui.ErrorPage(ctxt, ENOPERM)
}
comm := ctxt.CurrentCommunity()
topic := ctxt.GetScratch("currentTopic").(*database.Topic)
flag, err := topic.IsSubscribed(ctxt.Ctx(), ctxt.CurrentUser())
if err != nil {
return ui.ErrorPage(ctxt, err)
}
err = topic.SetSubscribed(ctxt.Ctx(), ctxt.CurrentUser(), !flag)
if err != nil {
return ui.ErrorPage(ctxt, err)
}
return "redirect", fmt.Sprintf("/comm/%s/conf/%s/op/%d/manage", comm.Alias, ctxt.GetScratch("currentAlias"), topic.Number), nil
}
/* TopicRemoveBozo removes filtering from a specified user in the topic.
* Parameters:
* ctxt - The AmContext for the request.
+30
View File
@@ -240,6 +240,36 @@ func (t *Topic) GetBozos(ctx context.Context, u *User) ([]TopicBozo, error) {
return rc, nil
}
// IsSubscribed returns true if the given user is subscribed to receive E-mails of topic posts.
func (t *Topic) IsSubscribed(ctx context.Context, u *User) (bool, error) {
row := amdb.QueryRowContext(ctx, "SELECT subscribe FROM topicsettings WHERE topicid = ? AND uid = ?", t.TopicId, u.Uid)
var rc bool
err := row.Scan(&rc)
switch err {
case nil:
return rc, nil
case sql.ErrNoRows:
return false, nil
}
return false, err
}
// SetSubscribed sets the "subscribed" flag for the given user.
func (t *Topic) SetSubscribed(ctx context.Context, u *User, flag bool) error {
if u.IsAnon {
return nil
}
rs, err := amdb.ExecContext(ctx, "UPDATE topicsettings SET subscribe = ? WHERE topicid = ? AND uid = ?", flag, t.TopicId, u.Uid)
if err == nil {
var rows int64
rows, err = rs.RowsAffected()
if err == nil && rows == 0 {
_, err = amdb.ExecContext(ctx, "INSERT INTO topicsettings (topicid, uid, subscribe)", t.TopicId, u.Uid, flag)
}
}
return err
}
// GetSubscribers returns an array of UIDs of every user that subscribed to the topic.
func (t *Topic) GetSubscribers(ctx context.Context) ([]int32, error) {
rs, err := amdb.QueryContext(ctx, "SELECT uid FROM topicsettings WHERE topicid = ? AND subscribe <> 0", t.TopicId)
+1 -1
View File
@@ -33,7 +33,7 @@ _(italicized items can be deferred)_
- Posts view:
- Find
- Manage:
- Subscribe to Topic
- ~~Subscribe to Topic~~
- Send invite
- ~~Filtered Users (list/remove)~~
- ~~Stick/Unstick~~
+1
View File
@@ -114,6 +114,7 @@ func setupEcho() *echo.Echo {
opsGroup.GET("/scribble/:msg", ui.AmWrap(ScribbleMessage))
opsGroup.GET("/nuke/:msg", ui.AmWrap(NukeMessage))
opsGroup.GET("/manage", ui.AmWrap(TopicManage))
opsGroup.GET("/subscribe", ui.AmWrap(TopicSetSubscribe))
opsGroup.GET("/rmbozo/:uid", ui.AmWrap(TopicRemoveBozo))
return e
+1 -1
View File
@@ -29,7 +29,7 @@
{{ end }}
</div>
<div class="mb-4">
<a class="text-blue-700 hover:text-blue-900 text-sm font-bold" href="/TODO/{{ opsLink }}/subscribe">
<a class="text-blue-700 hover:text-blue-900 text-sm font-bold" href="{{ opsLink }}/subscribe">
{{ if subscribed }}
Click Here To Stop Subscribing To This Topic
{{ else }}