From ac30cb5e4d1740eddc91944213f7e86aa0d5ee1a Mon Sep 17 00:00:00 2001
From: LittleSheep <littlesheep.code@hotmail.com>
Date: Sat, 5 Apr 2025 12:17:48 +0800
Subject: [PATCH] :sparkles: Community mod able to uncollapse post

---
 pkg/internal/http/api/index.go     |  1 +
 pkg/internal/http/api/posts_api.go | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/pkg/internal/http/api/index.go b/pkg/internal/http/api/index.go
index 28ebeba..b95e8d5 100644
--- a/pkg/internal/http/api/index.go
+++ b/pkg/internal/http/api/index.go
@@ -67,6 +67,7 @@ func MapControllers(app *fiber.App, baseURL string) {
 			posts.Post("/:postId/flag", createFlag)
 			posts.Post("/:postId/react", reactPost)
 			posts.Post("/:postId/pin", pinPost)
+			posts.Post("/:postId/uncollapse", uncollapsePost)
 			posts.Delete("/:postId", deletePost)
 
 			posts.Get("/:postId/replies", listPostReplies)
diff --git a/pkg/internal/http/api/posts_api.go b/pkg/internal/http/api/posts_api.go
index 005b2a1..1232e65 100644
--- a/pkg/internal/http/api/posts_api.go
+++ b/pkg/internal/http/api/posts_api.go
@@ -372,3 +372,17 @@ func pinPost(c *fiber.Ctx) error {
 		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)
+}