From 5e4f829b9c26e40bc3931226d4fa0872c150e43a Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 5 Jun 2022 11:19:18 -0700 Subject: auto subscribe in place. still have to do some logic changes for bugs --- route/routes/boardmgmt.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'route/routes') diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go index 5d6dd93..04c01b5 100644 --- a/route/routes/boardmgmt.go +++ b/route/routes/boardmgmt.go @@ -347,9 +347,34 @@ func BoardPopArchive(ctx *fiber.Ctx) error { return ctx.SendString("board pop archive") } -// TODO routes/BoardAutoSubscribe func BoardAutoSubscribe(ctx *fiber.Ctx) error { - return ctx.SendString("board auto subscribe") + actor, err := activitypub.GetActorFromDB(config.Domain) + + if err != nil { + return util.MakeError(err, "BoardAutoSubscribe") + } + + if has := actor.HasValidation(ctx); !has { + return util.MakeError(err, "BoardAutoSubscribe") + } + + board := ctx.Query("board") + + if actor, err = activitypub.GetActorByNameFromDB(board); err != nil { + return util.MakeError(err, "BoardAutoSubscribe") + } + + if err := actor.SetAutoSubscribe(); err != nil { + return util.MakeError(err, "BoardAutoSubscribe") + } + + if autoSub, _ := actor.GetAutoSubscribe(); autoSub { + if err := actor.AutoFollow(); err != nil { + return util.MakeError(err, "BoardAutoSubscribe") + } + } + + return ctx.Redirect("/"+config.Key+"/"+board, http.StatusSeeOther) } func BoardBlacklist(ctx *fiber.Ctx) error { -- cgit v1.2.3