From 25829d2d0e379c323b8f2ae6e7c2aad7548f0a30 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sat, 18 Jun 2022 13:57:30 -0700 Subject: sticky and lock implemented --- route/routes/boardmgmt.go | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'route/routes/boardmgmt.go') 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) + } +} -- cgit v1.2.3