implemented hide/show message functionality
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -23,6 +24,8 @@ import (
|
||||
"git.erbosoft.com/amy/amsterdam/ui"
|
||||
)
|
||||
|
||||
var ENOPERM error = errors.New("you are not permitted to perform this operation")
|
||||
|
||||
// slurpFile reads the contrents of a multipart.File into memory.
|
||||
func slurpFile(file *multipart.FileHeader) ([]byte, error) {
|
||||
f, err := file.Open()
|
||||
@@ -139,3 +142,40 @@ func HideTopic(ctxt ui.AmContext) (string, any, error) {
|
||||
}
|
||||
return "redirect", fmt.Sprintf("/comm/%s/conf/%s/r/%d", ctxt.CurrentCommunity().Alias, ctxt.GetScratch("currentAlias"), topic.Number), nil
|
||||
}
|
||||
|
||||
/* HideMessage hides or shows a topic message.
|
||||
* 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 HideMessage(ctxt ui.AmContext) (string, any, error) {
|
||||
if ctxt.CurrentUser().IsAnon {
|
||||
ctxt.SetRC(http.StatusForbidden)
|
||||
return ui.ErrorPage(ctxt, ENOPERM)
|
||||
}
|
||||
conf := ctxt.GetScratch("currentConference").(*database.Conference)
|
||||
myLevel := ctxt.GetScratch("levelInConference").(uint16)
|
||||
topic := ctxt.GetScratch("currentTopic").(*database.Topic)
|
||||
msgNum, err := strconv.Atoi(ctxt.URLParam("msg"))
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
hdrs, err := database.AmGetPostRange(ctxt.Ctx(), topic, int32(msgNum), int32(msgNum))
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
} else if len(hdrs) != 1 {
|
||||
return ui.ErrorPage(ctxt, errors.New("internal error getting post reference"))
|
||||
}
|
||||
if (hdrs[0].CreatorUid != ctxt.CurrentUserId()) && !conf.TestPermission("Conference.Hide", myLevel) {
|
||||
ctxt.SetRC(http.StatusForbidden)
|
||||
return ui.ErrorPage(ctxt, ENOPERM)
|
||||
}
|
||||
err = hdrs[0].SetHidden(ctxt.Ctx(), ctxt.CurrentUser(), !(hdrs[0].Hidden), ctxt.RemoteIP())
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
return "redirect", fmt.Sprintf("/comm/%s/conf/%s/r/%d?r=%d&ac=1", ctxt.CurrentCommunity().Alias, ctxt.GetScratch("currentAlias"), topic.Number, hdrs[0].Num), nil
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ func setupEcho() *echo.Echo {
|
||||
confGroup.POST("/r/:topic", ui.AmWrap(PostInTopic), ui.SetTopic)
|
||||
opsGroup := confGroup.Group("/op/:topic", ui.SetTopic)
|
||||
opsGroup.GET("/hide", ui.AmWrap(HideTopic))
|
||||
opsGroup.GET("/hide/:msg", ui.AmWrap(HideMessage))
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@
|
||||
{{ if advancedControls }}
|
||||
<div class="flex flex-col gap-2">
|
||||
{{ if canHide }}
|
||||
<a href="/TODO"
|
||||
<a href="{{ topicListLink }}/op/{{ topicNum }}/hide/{{ p.Num }}"
|
||||
class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">
|
||||
{{ if isPostHidden }}Show{{ else }}Hide{{ end }}
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user