Noah
6c91c67c97
* Users who set their Profile Picture to "friends only" or "private" can have their avatar be private all over the website to users who are not their friends or not granted access. * Users who are not your friends see a yellow placeholder avatar, and users not granted access to a private Profile Pic sees a purple avatar. * Admin users see these same placeholder avatars most places too (on search, forums, comments, etc.) if the user did not friend or grant the admin. But admins ALWAYS see it on their Profile Page directly, for ability to moderate. * Fix marking Notifications as read: clicking the link in an unread notification now will wait on the ajax request to finish before allowing the redirect. * Update the FAQ
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package friend
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/config"
|
|
"code.nonshy.com/nonshy/website/pkg/models"
|
|
"code.nonshy.com/nonshy/website/pkg/session"
|
|
"code.nonshy.com/nonshy/website/pkg/templates"
|
|
)
|
|
|
|
// Friends list and pending friend request endpoint.
|
|
func Friends() http.HandlerFunc {
|
|
tmpl := templates.Must("friend/friends.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var (
|
|
view = r.FormValue("view")
|
|
isRequests = view == "requests"
|
|
isPending = view == "pending"
|
|
)
|
|
|
|
currentUser, err := session.CurrentUser(r)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Unexpected error: could not get currentUser.")
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
// Get our friends.
|
|
pager := &models.Pagination{
|
|
PerPage: config.PageSizeFriends,
|
|
Sort: "updated_at desc",
|
|
}
|
|
pager.ParsePage(r)
|
|
friends, err := models.PaginateFriends(currentUser, isRequests, isPending, pager)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't paginate friends: %s", err)
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
// Inject relationship booleans.
|
|
models.SetUserRelationships(currentUser, friends)
|
|
|
|
var vars = map[string]interface{}{
|
|
"IsRequests": isRequests,
|
|
"IsPending": isPending,
|
|
"Friends": friends,
|
|
"Pager": pager,
|
|
}
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|