2018-03-17 08:16:43 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2019-04-19 06:36:26 +00:00
|
|
|
c "github.com/Azareal/Gosora/common"
|
2018-11-01 06:43:56 +00:00
|
|
|
"github.com/Azareal/Gosora/common/phrases"
|
2018-03-17 08:16:43 +00:00
|
|
|
)
|
|
|
|
|
2020-02-11 03:13:38 +00:00
|
|
|
func ForumList(w http.ResponseWriter, r *http.Request, user c.User, h *c.Header) c.RouteError {
|
|
|
|
skip, rerr := h.Hooks.VhookSkippable("route_forum_list_start", w, r, &user, h)
|
2019-04-28 10:50:45 +00:00
|
|
|
if skip || rerr != nil {
|
|
|
|
return rerr
|
|
|
|
}
|
2020-02-11 03:13:38 +00:00
|
|
|
h.Title = phrases.GetTitlePhrase("forums")
|
|
|
|
h.Zone = "forums"
|
|
|
|
h.Path = "/forums/"
|
|
|
|
h.MetaDesc = h.Settings["meta_desc"].(string)
|
2018-03-17 08:16:43 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
var canSee []int
|
|
|
|
if user.IsSuperAdmin {
|
2019-04-19 06:36:26 +00:00
|
|
|
canSee, err = c.Forums.GetAllVisibleIDs()
|
2018-03-17 08:16:43 +00:00
|
|
|
if err != nil {
|
2019-04-19 06:36:26 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-03-17 08:16:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-04-19 06:36:26 +00:00
|
|
|
group, err := c.Groups.Get(user.Group)
|
2018-03-17 08:16:43 +00:00
|
|
|
if err != nil {
|
2019-04-19 06:36:26 +00:00
|
|
|
log.Printf("Group #%d doesn't exist despite being used by c.User #%d", user.Group, user.ID)
|
|
|
|
return c.LocalError("Something weird happened", w, r, user)
|
2018-03-17 08:16:43 +00:00
|
|
|
}
|
|
|
|
canSee = group.CanSee
|
|
|
|
}
|
|
|
|
|
2019-06-18 04:13:47 +00:00
|
|
|
var forumList []c.Forum
|
2018-03-17 08:16:43 +00:00
|
|
|
for _, fid := range canSee {
|
|
|
|
// Avoid data races by copying the struct into something we can freely mold without worrying about breaking something somewhere else
|
2019-10-06 00:34:09 +00:00
|
|
|
f := c.Forums.DirtyGet(fid).Copy()
|
|
|
|
if f.ParentID == 0 && f.Name != "" && f.Active {
|
|
|
|
if f.LastTopicID != 0 {
|
|
|
|
if f.LastTopic.ID != 0 && f.LastReplyer.ID != 0 {
|
|
|
|
f.LastTopicTime = c.RelativeTime(f.LastTopic.LastReplyAt)
|
2018-03-17 08:16:43 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-11 03:13:38 +00:00
|
|
|
h.Hooks.Hook("forums_frow_assign", &f)
|
2019-10-06 00:34:09 +00:00
|
|
|
forumList = append(forumList, f)
|
2018-03-17 08:16:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 03:13:38 +00:00
|
|
|
return renderTemplate("forums", w, r, h, c.ForumsPage{h, forumList})
|
2018-03-17 08:16:43 +00:00
|
|
|
}
|