Noah
030fadcf8d
Implement block lists. They work like friend lists but are unidirectional, but take effect in both directions (blocker and blockee can not see one another on the site -- except admin users can always see all users). * Profile page says 404 * User gallery says 404 * User search page filters out blocked users * Compose endpoint blocks sending messages to blocked users (except admin) * Site Gallery filters photos by blocked (and uncertified) users * Inbox page hides chat list for blocked users (can still read the chat history if you have a link to the old thread)
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package photo
|
|
|
|
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"
|
|
)
|
|
|
|
// SiteGallery controller (/photo/gallery) to view all members' public gallery pics.
|
|
func SiteGallery() http.HandlerFunc {
|
|
tmpl := templates.Must("photo/gallery.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Query params.
|
|
var (
|
|
viewStyle = r.FormValue("view") // cards (default), full
|
|
)
|
|
if viewStyle != "full" {
|
|
viewStyle = "cards"
|
|
}
|
|
|
|
// Load the current user.
|
|
currentUser, err := session.CurrentUser(r)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Unexpected error: couldn't get CurrentUser")
|
|
}
|
|
|
|
// Get the page of photos.
|
|
pager := &models.Pagination{
|
|
Page: 1,
|
|
PerPage: config.PageSizeSiteGallery,
|
|
Sort: "created_at desc",
|
|
}
|
|
pager.ParsePage(r)
|
|
photos, err := models.PaginateGalleryPhotos(currentUser.ID, currentUser.IsAdmin, currentUser.Explicit, pager)
|
|
|
|
// Bulk load the users associated with these photos.
|
|
var userIDs = []uint64{}
|
|
for _, photo := range photos {
|
|
userIDs = append(userIDs, photo.UserID)
|
|
}
|
|
userMap, err := models.MapUsers(userIDs)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Failed to MapUsers: %s", err)
|
|
}
|
|
|
|
var vars = map[string]interface{}{
|
|
"IsSiteGallery": true,
|
|
"Photos": photos,
|
|
"UserMap": userMap,
|
|
"Pager": pager,
|
|
"ViewStyle": viewStyle,
|
|
}
|
|
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|