diff --git a/pkg/config/config.go b/pkg/config/config.go index 3a93a2f..54c9be3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -124,7 +124,7 @@ const ( ThreadViewDebounceCooldown = 1 * time.Hour // Enable user-owned forums (feature flag) - UserForumsEnabled = true + UserForumsEnabled = false ) // User-Owned Forums: Quota settings for how many forums a user can own. diff --git a/pkg/controller/forum/search.go b/pkg/controller/forum/search.go index 0c8f060..acc06a4 100644 --- a/pkg/controller/forum/search.go +++ b/pkg/controller/forum/search.go @@ -25,6 +25,8 @@ func Search() http.HandlerFunc { searchTerm = r.FormValue("q") byUsername = r.FormValue("username") postType = r.FormValue("type") + inForum = r.FormValue("in") + categories = []string{} sort = r.FormValue("sort") sortOK bool ) @@ -45,6 +47,14 @@ func Search() http.HandlerFunc { postType = "all" } + // In forums + switch inForum { + case "official": + categories = config.ForumCategories + case "community": + categories = []string{""} + } + // Get the current user. currentUser, err := session.CurrentUser(r) if err != nil { @@ -80,7 +90,7 @@ func Search() http.HandlerFunc { ) pager.ParsePage(r) - posts, err := models.SearchForum(currentUser, search, filters, pager) + posts, err := models.SearchForum(currentUser, categories, search, filters, pager) if err != nil { session.FlashError(w, r, "Couldn't search the forums: %s", err) templates.Redirect(w, "/") @@ -109,6 +119,7 @@ func Search() http.HandlerFunc { "SearchTerm": searchTerm, "ByUsername": byUsername, "Type": postType, + "InForum": inForum, "Sort": sort, } if err := tmpl.Execute(w, r, vars); err != nil { diff --git a/pkg/models/forum_search.go b/pkg/models/forum_search.go index e1f047d..0e47333 100644 --- a/pkg/models/forum_search.go +++ b/pkg/models/forum_search.go @@ -81,7 +81,7 @@ type ForumSearchFilters struct { } // SearchForum searches the forum. -func SearchForum(user *User, search *Search, filters ForumSearchFilters, pager *Pagination) ([]*Comment, error) { +func SearchForum(user *User, categories []string, search *Search, filters ForumSearchFilters, pager *Pagination) ([]*Comment, error) { var ( coms = []*Comment{} query = (&Comment{}).Preload() @@ -90,6 +90,11 @@ func SearchForum(user *User, search *Search, filters ForumSearchFilters, pager * placeholders = []interface{}{} ) + if len(categories) > 0 { + wheres = append(wheres, "category IN ?") + placeholders = append(placeholders, categories) + } + // Hide explicit forum if user hasn't opted into it. if !user.Explicit && !user.IsAdmin { wheres = append(wheres, "forums.explicit = false") diff --git a/web/templates/faq.html b/web/templates/faq.html index 2c95073..d3a0a73 100644 --- a/web/templates/faq.html +++ b/web/templates/faq.html @@ -873,11 +873,11 @@

Can I create my own forums?

+ {{if .FeatureUserForumsEnabled}}

NEW: August 30, 2024

- {{if .FeatureUserForumsEnabled}}

Yes! As of August 30, 2024 (the two-year anniversary of {{PrettyTitle}}), we now have Community Forums where members are allowed to create their own diff --git a/web/templates/forum/add_edit.html b/web/templates/forum/add_edit.html index d222848..3085f04 100644 --- a/web/templates/forum/add_edit.html +++ b/web/templates/forum/add_edit.html @@ -85,7 +85,7 @@

- {{if .CurrentUser.IsAdmin}} + {{if .CurrentUser.HasAdminScope "admin.forum.manage"}}
-
+
@@ -78,6 +78,24 @@
+ {{if .FeatureUserForumsEnabled}} +
+
+ +
+ +
+
+
+ {{end}} +