github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/routes/forum_list.go (about) 1 package routes 2 3 import ( 4 "log" 5 "net/http" 6 7 c "github.com/Azareal/Gosora/common" 8 "github.com/Azareal/Gosora/common/phrases" 9 ) 10 11 func ForumList(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError { 12 /*skip, rerr := h.Hooks.VhookSkippable("route_forum_list_start", w, r, u, h) 13 if skip || rerr != nil { 14 return rerr 15 }*/ 16 skip, rerr := c.H_route_forum_list_start_hook(h.Hooks, w, r, u, h) 17 if skip || rerr != nil { 18 return rerr 19 } 20 h.Title = phrases.GetTitlePhrase("forums") 21 h.Zone = "forums" 22 h.Path = "/forums/" 23 h.MetaDesc = h.Settings["meta_desc"].(string) 24 25 var err error 26 var canSee []int 27 if u.IsSuperAdmin { 28 canSee, err = c.Forums.GetAllVisibleIDs() 29 if err != nil { 30 return c.InternalError(err, w, r) 31 } 32 } else { 33 g, err := c.Groups.Get(u.Group) 34 if err != nil { 35 log.Printf("Group #%d doesn't exist despite being used by c.User #%d", u.Group, u.ID) 36 return c.LocalError("Something weird happened", w, r, u) 37 } 38 canSee = g.CanSee 39 } 40 41 var forumList []c.Forum 42 for _, fid := range canSee { 43 // Avoid data races by copying the struct into something we can freely mold without worrying about breaking something somewhere else 44 f := c.Forums.DirtyGet(fid).Copy() 45 if f.ParentID == 0 && f.Name != "" && f.Active { 46 if f.LastTopicID != 0 { 47 if f.LastTopic.ID != 0 && f.LastReplyer.ID != 0 { 48 f.LastTopicTime = c.RelativeTime(f.LastTopic.LastReplyAt) 49 } 50 } 51 //h.Hooks.Hook("forums_frow_assign", &f) 52 c.H_forums_frow_assign_hook(h.Hooks, &f) 53 forumList = append(forumList, f) 54 } 55 } 56 57 return renderTemplate("forums", w, r, h, c.ForumsPage{h, forumList}) 58 }