Noah
93c13882aa
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.
117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
package templates
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"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"
|
|
)
|
|
|
|
// MergeVars mixes in globally available template variables. The http.Request is optional.
|
|
func MergeVars(r *http.Request, m map[string]interface{}) {
|
|
m["Title"] = config.Title
|
|
m["BuildHash"] = config.RuntimeBuild
|
|
m["BuildDate"] = config.RuntimeBuildDate
|
|
m["Subtitle"] = config.Subtitle
|
|
m["YYYY"] = time.Now().Year()
|
|
|
|
if r == nil {
|
|
return
|
|
}
|
|
|
|
m["Request"] = r
|
|
}
|
|
|
|
// MergeUserVars mixes in global template variables: LoggedIn and CurrentUser. The http.Request is optional.
|
|
func MergeUserVars(r *http.Request, m map[string]interface{}) {
|
|
// Defaults
|
|
m["LoggedIn"] = false
|
|
m["CurrentUser"] = nil
|
|
m["SessionImpersonated"] = false
|
|
|
|
// User notification counts for nav bar.
|
|
m["NavUnreadMessages"] = 0 // New messages
|
|
m["NavFriendRequests"] = 0 // Friend requests
|
|
m["NavUnreadNotifications"] = 0 // general notifications
|
|
m["NavTotalNotifications"] = 0 // Total of above
|
|
|
|
// Admin notification counts for nav bar.
|
|
m["NavCertificationPhotos"] = 0 // Cert. photos needing approval
|
|
m["NavAdminFeedback"] = 0 // Unacknowledged feedback
|
|
m["NavAdminNotifications"] = 0 // Total of above
|
|
|
|
if r == nil {
|
|
return
|
|
}
|
|
|
|
m["SessionImpersonated"] = session.Impersonated(r)
|
|
|
|
if user, err := session.CurrentUser(r); err == nil {
|
|
m["LoggedIn"] = true
|
|
m["CurrentUser"] = user
|
|
|
|
// Get user recent notifications.
|
|
/*notifPager := &models.Pagination{
|
|
Page: 1,
|
|
PerPage: 10,
|
|
}
|
|
if notifs, err := models.PaginateNotifications(user, notifPager); err == nil {
|
|
m["Notifications"] = notifs
|
|
}*/
|
|
|
|
// Collect notification counts.
|
|
var (
|
|
// For users
|
|
countMessages int64
|
|
countFriendReqs int64
|
|
countNotifications int64
|
|
|
|
// For admins
|
|
countCertPhotos int64
|
|
countFeedback int64
|
|
)
|
|
|
|
// Get unread message count.
|
|
if count, err := models.CountUnreadMessages(user.ID); err == nil {
|
|
m["NavUnreadMessages"] = count
|
|
countMessages = count
|
|
} else {
|
|
log.Error("MergeUserVars: couldn't CountUnreadMessages for %d: %s", user.ID, err)
|
|
}
|
|
|
|
// Get friend request count.
|
|
if count, err := models.CountFriendRequests(user.ID); err == nil {
|
|
m["NavFriendRequests"] = count
|
|
countFriendReqs = count
|
|
} else {
|
|
log.Error("MergeUserVars: couldn't CountFriendRequests for %d: %s", user.ID, err)
|
|
}
|
|
|
|
// Count other notifications.
|
|
if count, err := models.CountUnreadNotifications(user.ID); err == nil {
|
|
m["NavUnreadNotifications"] = count
|
|
countNotifications = count
|
|
} else {
|
|
log.Error("MergeUserVars: couldn't CountFriendRequests for %d: %s", user.ID, err)
|
|
}
|
|
|
|
// Are we admin?
|
|
if user.IsAdmin {
|
|
// Any pending certification photos or feedback?
|
|
countCertPhotos = models.CountCertificationPhotosNeedingApproval()
|
|
countFeedback = models.CountUnreadFeedback()
|
|
m["NavCertificationPhotos"] = countCertPhotos
|
|
m["NavAdminFeedback"] = countFeedback
|
|
|
|
// Total notification count for admin actions.
|
|
m["NavAdminNotifications"] = countCertPhotos + countFeedback
|
|
}
|
|
|
|
// Total count for user notifications.
|
|
m["NavTotalNotifications"] = countMessages + countFriendReqs + countNotifications + countCertPhotos + countFeedback
|
|
}
|
|
}
|