Compare commits

...

2 Commits

Author SHA1 Message Date
ac30cb5e4d Community mod able to uncollapse post 2025-04-05 12:17:48 +08:00
d189c5a8d8 👔 Updated collapse post 2025-04-05 12:12:57 +08:00
4 changed files with 19 additions and 3 deletions

View File

@ -67,6 +67,7 @@ func MapControllers(app *fiber.App, baseURL string) {
posts.Post("/:postId/flag", createFlag) posts.Post("/:postId/flag", createFlag)
posts.Post("/:postId/react", reactPost) posts.Post("/:postId/react", reactPost)
posts.Post("/:postId/pin", pinPost) posts.Post("/:postId/pin", pinPost)
posts.Post("/:postId/uncollapse", uncollapsePost)
posts.Delete("/:postId", deletePost) posts.Delete("/:postId", deletePost)
posts.Get("/:postId/replies", listPostReplies) posts.Get("/:postId/replies", listPostReplies)

View File

@ -372,3 +372,17 @@ func pinPost(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNoContent) return c.SendStatus(fiber.StatusNoContent)
} }
} }
func uncollapsePost(c *fiber.Ctx) error {
id, _ := c.ParamsInt("postId", 0)
if err := sec.EnsureGrantedPerm(c, "UncollapsePosts", true); err != nil {
return err
}
if err := database.C.Model(&models.Post{}).Where("id = ?", id).Update("is_collapsed", false).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}
return c.SendStatus(fiber.StatusOK)
}

View File

@ -26,6 +26,10 @@ func NewFlag(post models.Post, account uint) (models.PostFlag, error) {
} }
func FlagCalculateCollapseStatus(post models.Post) error { func FlagCalculateCollapseStatus(post models.Post) error {
if post.TotalViews <= 2 {
return nil
}
collapseLimit := 0.5 collapseLimit := 0.5
var flagCount int64 var flagCount int64

View File

@ -48,9 +48,6 @@ func UniversalPostFilter(c *fiber.Ctx, tx *gorm.DB, cfg ...UniversalPostFilterCo
if c.QueryBool("noReply", true) && !config.ShowReply { if c.QueryBool("noReply", true) && !config.ShowReply {
tx = FilterPostReply(tx) tx = FilterPostReply(tx)
} }
if c.QueryBool("noCollapse", true) && !config.ShowCollapsed {
tx = tx.Where("is_collapsed = ? OR is_collapsed IS NULL", false)
}
if len(c.Query("author")) > 0 { if len(c.Query("author")) > 0 {
var author models.Publisher var author models.Publisher