Noah Petherbridge
bb08ec56ce
Finish implementing the basic forum features: * Pinned threads (admin or board owner only) * Edit Thread settings when you edit the top-most comment. * NoReply threads remove all the reply buttons. * Explicit forums and threads are filtered out unless opted-in (admins always see them). * Count the unique members who participated in each forum. * Get the most recently updated thread to show on forum list page. * Contact/Report page: handle receiving a comment ID to report on. Implement Likes & Notifications * Like buttons added to Photos and Profile Pages. Implemented via simple vanilla JS (likes.js) to make ajax requests to back-end to like/unlike. * Notifications: for your photo or profile being liked. If you unlike, the existing notifications about the like are revoked. * The notifications appear as an alert number in the nav bar and are read on the User Dashboard. Click to mark a notification as "read" or click the "mark all as read" button. Update DeleteUser to scrub likes, notifications, threads, and comments.
86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
package forum
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/config"
|
|
"git.kirsle.net/apps/gosocial/pkg/log"
|
|
"git.kirsle.net/apps/gosocial/pkg/models"
|
|
"git.kirsle.net/apps/gosocial/pkg/session"
|
|
"git.kirsle.net/apps/gosocial/pkg/templates"
|
|
)
|
|
|
|
// Forum view for a specific board index.
|
|
func Forum() http.HandlerFunc {
|
|
tmpl := templates.Must("forum/board_index.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Parse the path parameters
|
|
var (
|
|
forum *models.Forum
|
|
)
|
|
|
|
if m := ForumPathRegexp.FindStringSubmatch(r.URL.Path); m == nil {
|
|
log.Error("Regexp failed to parse: %s", r.URL.Path)
|
|
templates.NotFoundPage(w, r)
|
|
return
|
|
} else {
|
|
// Look up the forum itself.
|
|
if found, err := models.ForumByFragment(m[1]); err != nil {
|
|
templates.NotFoundPage(w, r)
|
|
return
|
|
} else {
|
|
forum = found
|
|
}
|
|
}
|
|
|
|
// Get the current user.
|
|
currentUser, err := session.CurrentUser(r)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't get current user: %s", err)
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
// Get the pinned threads.
|
|
pinned, err := models.PinnedThreads(forum)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't get pinned threads: %s", err)
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
// Get all the categorized index forums.
|
|
// XXX: we get a large page size to get ALL official forums
|
|
var pager = &models.Pagination{
|
|
Page: 1,
|
|
PerPage: config.PageSizeThreadList,
|
|
Sort: "updated_at desc",
|
|
}
|
|
pager.ParsePage(r)
|
|
|
|
threads, err := models.PaginateThreads(currentUser, forum, pager)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't paginate threads: %s", err)
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
// Inject pinned threads on top.
|
|
threads = append(pinned, threads...)
|
|
|
|
// Map the statistics (replies, views) of these threads.
|
|
threadMap := models.MapThreadStatistics(threads)
|
|
|
|
var vars = map[string]interface{}{
|
|
"Forum": forum,
|
|
"Threads": threads,
|
|
"ThreadMap": threadMap,
|
|
"Pager": pager,
|
|
}
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|