added topic subscribe/unsubscribe
This commit is contained in:
+33
-2
@@ -429,6 +429,13 @@ func TopicManage(ctxt ui.AmContext) (string, any, error) {
|
|||||||
}
|
}
|
||||||
ctxt.VarMap().Set("canInvite", member)
|
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.
|
// Get the filtered users list.
|
||||||
bozos, err := topic.GetBozos(ctxt.Ctx(), ctxt.CurrentUser())
|
bozos, err := topic.GetBozos(ctxt.Ctx(), ctxt.CurrentUser())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -436,12 +443,36 @@ func TopicManage(ctxt ui.AmContext) (string, any, error) {
|
|||||||
}
|
}
|
||||||
ctxt.VarMap().Set("bozos", bozos)
|
ctxt.VarMap().Set("bozos", bozos)
|
||||||
|
|
||||||
ctxt.VarMap().Set("subscribed", false) // TODO
|
|
||||||
|
|
||||||
ctxt.VarMap().Set("amsterdam_pageTitle", "Manage Topic: "+topic.Name)
|
ctxt.VarMap().Set("amsterdam_pageTitle", "Manage Topic: "+topic.Name)
|
||||||
return "framed_template", "manage_topic.jet", nil
|
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.
|
/* TopicRemoveBozo removes filtering from a specified user in the topic.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ctxt - The AmContext for the request.
|
* ctxt - The AmContext for the request.
|
||||||
|
|||||||
@@ -240,6 +240,36 @@ func (t *Topic) GetBozos(ctx context.Context, u *User) ([]TopicBozo, error) {
|
|||||||
return rc, nil
|
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.
|
// GetSubscribers returns an array of UIDs of every user that subscribed to the topic.
|
||||||
func (t *Topic) GetSubscribers(ctx context.Context) ([]int32, error) {
|
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)
|
rs, err := amdb.QueryContext(ctx, "SELECT uid FROM topicsettings WHERE topicid = ? AND subscribe <> 0", t.TopicId)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ _(italicized items can be deferred)_
|
|||||||
- Posts view:
|
- Posts view:
|
||||||
- Find
|
- Find
|
||||||
- Manage:
|
- Manage:
|
||||||
- Subscribe to Topic
|
- ~~Subscribe to Topic~~
|
||||||
- Send invite
|
- Send invite
|
||||||
- ~~Filtered Users (list/remove)~~
|
- ~~Filtered Users (list/remove)~~
|
||||||
- ~~Stick/Unstick~~
|
- ~~Stick/Unstick~~
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ func setupEcho() *echo.Echo {
|
|||||||
opsGroup.GET("/scribble/:msg", ui.AmWrap(ScribbleMessage))
|
opsGroup.GET("/scribble/:msg", ui.AmWrap(ScribbleMessage))
|
||||||
opsGroup.GET("/nuke/:msg", ui.AmWrap(NukeMessage))
|
opsGroup.GET("/nuke/:msg", ui.AmWrap(NukeMessage))
|
||||||
opsGroup.GET("/manage", ui.AmWrap(TopicManage))
|
opsGroup.GET("/manage", ui.AmWrap(TopicManage))
|
||||||
|
opsGroup.GET("/subscribe", ui.AmWrap(TopicSetSubscribe))
|
||||||
opsGroup.GET("/rmbozo/:uid", ui.AmWrap(TopicRemoveBozo))
|
opsGroup.GET("/rmbozo/:uid", ui.AmWrap(TopicRemoveBozo))
|
||||||
|
|
||||||
return e
|
return e
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-4">
|
<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 }}
|
{{ if subscribed }}
|
||||||
Click Here To Stop Subscribing To This Topic
|
Click Here To Stop Subscribing To This Topic
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
|||||||
Reference in New Issue
Block a user