aboutsummaryrefslogtreecommitdiff
path: root/route/routes/boardmgmt.go
diff options
context:
space:
mode:
authorFChannel <>2022-06-18 13:57:30 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit25829d2d0e379c323b8f2ae6e7c2aad7548f0a30 (patch)
treec828eb5bb04ce04141c717c26b637a59b32ab979 /route/routes/boardmgmt.go
parentf3d1683d6562afb30522afb98fb3a22456473275 (diff)
sticky and lock implemented
Diffstat (limited to 'route/routes/boardmgmt.go')
-rw-r--r--route/routes/boardmgmt.go96
1 files changed, 96 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)
+ }
+}