diff options
-rw-r--r-- | activitypub/actor.go | 6 | ||||
-rw-r--r-- | route/routes/boardmgmt.go | 29 |
2 files changed, 30 insertions, 5 deletions
diff --git a/activitypub/actor.go b/activitypub/actor.go index aa1081f..ea4ff3b 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -881,17 +881,17 @@ func (actor Actor) ReportedResp(ctx *fiber.Ctx) error { return util.MakeError(err, "GetReported") } -func (actor Actor) SetActorAutoSubscribeDB() error { +func (actor Actor) SetAutoSubscribe() error { current, err := actor.GetAutoSubscribe() if err != nil { - return util.MakeError(err, "SetActorAutoSubscribeDB") + return util.MakeError(err, "SetAutoSubscribe") } query := `update actor set autosubscribe=$1 where id=$2` _, err = config.DB.Exec(query, !current, actor.Id) - return util.MakeError(err, "SetActorAutoSubscribeDB") + return util.MakeError(err, "SetAutoSubscribe") } func (actor Actor) SendToFollowers(activity Activity) error { 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 { |