Noah Petherbridge
e06bf2f9c4
* Friends: can now see your sent requests awaiting approval too. * Site Gallery: you may see Friends-only photos on the Gallery if you are friends with the owner and the pic is opted-in for the Gallery. * Site Gallery: show color coded visibility icons in card headers. * Improve appearance of Upload Photo page. * Update FAQ
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package friend
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/config"
|
|
"git.kirsle.net/apps/gosocial/pkg/models"
|
|
"git.kirsle.net/apps/gosocial/pkg/session"
|
|
"git.kirsle.net/apps/gosocial/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.ID, isRequests, isPending, pager)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't paginate friends: %s", err)
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
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
|
|
}
|
|
})
|
|
}
|