2018-03-17 08:16:43 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2018-11-12 09:23:36 +00:00
|
|
|
func ForumList(w http.ResponseWriter, r *http.Request, user common.User, header *common.Header) common.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
|
|
|
|
var forumList []common.Forum
|
|
|
|
var canSee []int
|
|
|
|
if user.IsSuperAdmin {
|
|
|
|
canSee, err = common.Forums.GetAllVisibleIDs()
|
|
|
|
if err != nil {
|
|
|
|
return common.InternalError(err, w, r)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
group, err := common.Groups.Get(user.Group)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Group #%d doesn't exist despite being used by common.User #%d", user.Group, user.ID)
|
|
|
|
return common.LocalError("Something weird happened", w, r, user)
|
|
|
|
}
|
|
|
|
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
|
|
|
|
var forum = common.Forums.DirtyGet(fid).Copy()
|
|
|
|
if forum.ParentID == 0 && forum.Name != "" && forum.Active {
|
|
|
|
if forum.LastTopicID != 0 {
|
|
|
|
if forum.LastTopic.ID != 0 && forum.LastReplyer.ID != 0 {
|
|
|
|
forum.LastTopicTime = common.RelativeTime(forum.LastTopic.LastReplyAt)
|
|
|
|
} 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 05:02:29 +00:00
|
|
|
pi := common.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
|
|
|
}
|