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
|
|
|
)
|
|
|
|
|
2019-04-19 06:36:26 +00:00
|
|
|
func ForumList(w http.ResponseWriter, r *http.Request, user c.User, header *c.Header) c.RouteError {
|
2018-11-01 06:43:56 +00:00
|
|
|
header.Title = phrases.GetTitlePhrase("forums")
|
2018-04-22 12:33:56 +00:00
|
|
|
header.Zone = "forums"
|
2018-10-14 05:08:44 +00:00
|
|
|
header.Path = "/forums/"
|
2018-04-22 12:33:56 +00:00
|
|
|
header.MetaDesc = header.Settings["meta_desc"].(string)
|
2018-03-17 08:16:43 +00:00
|
|
|
|
|
|
|
var err error
|
2019-04-19 06:36:26 +00:00
|
|
|
var forumList []c.Forum
|
2018-03-17 08:16:43 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-19 06:36:26 +00:00
|
|
|
var forum = c.Forums.DirtyGet(fid).Copy()
|
2018-03-17 08:16:43 +00:00
|
|
|
if forum.ParentID == 0 && forum.Name != "" && forum.Active {
|
|
|
|
if forum.LastTopicID != 0 {
|
|
|
|
if forum.LastTopic.ID != 0 && forum.LastReplyer.ID != 0 {
|
2019-04-19 06:36:26 +00:00
|
|
|
forum.LastTopicTime = c.RelativeTime(forum.LastTopic.LastReplyAt)
|
2018-03-17 08:16:43 +00:00
|
|
|
} else {
|
|
|
|
forum.LastTopicTime = ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
forum.LastTopicTime = ""
|
|
|
|
}
|
2018-10-21 13:54:32 +00:00
|
|
|
header.Hooks.Hook("forums_frow_assign", &forum)
|
2018-03-17 08:16:43 +00:00
|
|
|
forumList = append(forumList, forum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 06:36:26 +00:00
|
|
|
pi := c.ForumsPage{header, forumList}
|
2018-11-12 09:23:36 +00:00
|
|
|
return renderTemplate("forums", w, r, header, pi)
|
2018-03-17 08:16:43 +00:00
|
|
|
}
|