aboutsummaryrefslogtreecommitdiff
path: root/route
diff options
context:
space:
mode:
Diffstat (limited to 'route')
-rw-r--r--route/routes/boardmgmt.go96
-rw-r--r--route/util.go6
2 files changed, 102 insertions, 0 deletions
diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go
index 5f24cdd..7ecc885 100644
--- a/route/routes/boardmgmt.go
+++ b/route/routes/boardmgmt.go
@@ -563,3 +563,99 @@ func ReportGet(ctx *fiber.Ctx) error {
return ctx.Render("report", fiber.Map{"page": data}, "layouts/main")
}
+
+func Sticky(ctx *fiber.Ctx) error {
+ id := ctx.Query("id")
+ board := ctx.Query("board")
+
+ actor, _ := activitypub.GetActorByNameFromDB(board)
+
+ _, auth := util.GetPasswordFromSession(ctx)
+
+ if id == "" || auth == "" {
+ return util.MakeError(errors.New("no auth"), "Sticky")
+ }
+
+ var obj = activitypub.ObjectBase{Id: id}
+ col, _ := obj.GetCollectionFromPath()
+
+ if len(col.OrderedItems) < 1 {
+ if has, _ := util.HasAuth(auth, actor.Id); !has {
+ return util.MakeError(errors.New("no auth"), "Sticky")
+ }
+
+ obj.MarkSticky(actor.Id)
+
+ return ctx.Redirect("/"+board, http.StatusSeeOther)
+ }
+
+ actor.Id = col.OrderedItems[0].Actor
+
+ var OP string
+ if len(col.OrderedItems[0].InReplyTo) > 0 && col.OrderedItems[0].InReplyTo[0].Id != "" {
+ OP = col.OrderedItems[0].InReplyTo[0].Id
+ } else {
+ OP = id
+ }
+
+ if has, _ := util.HasAuth(auth, actor.Id); !has {
+ return util.MakeError(errors.New("no auth"), "Sticky")
+ }
+
+ obj.MarkSticky(actor.Id)
+
+ var op = activitypub.ObjectBase{Id: OP}
+ if local, _ := op.IsLocal(); !local {
+ return ctx.Redirect("/"+board+"/"+util.RemoteShort(OP), http.StatusSeeOther)
+ } else {
+ return ctx.Redirect(OP, http.StatusSeeOther)
+ }
+}
+
+func Lock(ctx *fiber.Ctx) error {
+ id := ctx.Query("id")
+ board := ctx.Query("board")
+
+ actor, _ := activitypub.GetActorByNameFromDB(board)
+
+ _, auth := util.GetPasswordFromSession(ctx)
+
+ if id == "" || auth == "" {
+ return util.MakeError(errors.New("no auth"), "Lock")
+ }
+
+ var obj = activitypub.ObjectBase{Id: id}
+ col, _ := obj.GetCollectionFromPath()
+
+ if len(col.OrderedItems) < 1 {
+ if has, _ := util.HasAuth(auth, actor.Id); !has {
+ return util.MakeError(errors.New("no auth"), "Lock")
+ }
+
+ obj.MarkLocked(actor.Id)
+
+ return ctx.Redirect("/"+board, http.StatusSeeOther)
+ }
+
+ actor.Id = col.OrderedItems[0].Actor
+
+ var OP string
+ if len(col.OrderedItems[0].InReplyTo) > 0 && col.OrderedItems[0].InReplyTo[0].Id != "" {
+ OP = col.OrderedItems[0].InReplyTo[0].Id
+ } else {
+ OP = id
+ }
+
+ if has, _ := util.HasAuth(auth, actor.Id); !has {
+ return util.MakeError(errors.New("no auth"), "Lock")
+ }
+
+ obj.MarkLocked(actor.Id)
+
+ var op = activitypub.ObjectBase{Id: OP}
+ if local, _ := op.IsLocal(); !local {
+ return ctx.Redirect("/"+board+"/"+util.RemoteShort(OP), http.StatusSeeOther)
+ } else {
+ return ctx.Redirect(OP, http.StatusSeeOther)
+ }
+}
diff --git a/route/util.go b/route/util.go
index 09c5429..5a7d57c 100644
--- a/route/util.go
+++ b/route/util.go
@@ -139,6 +139,12 @@ func ParseOutboxRequest(ctx *fiber.Ctx, actor activitypub.Actor) error {
nObj.Actor = config.Domain + "/" + actor.Name
+ if locked, _ := nObj.InReplyTo[0].IsLocked(); locked {
+ ctx.Response().Header.SetStatusCode(403)
+ _, err := ctx.Write([]byte("thread is locked"))
+ return util.MakeError(err, "ParseOutboxRequest")
+ }
+
nObj, err = nObj.Write()
if err != nil {
return util.MakeError(err, "ParseOutboxRequest")