Noah Petherbridge
82f3914ae6
* On Forums landing page, show who was the most recent commenter on each board's most recently updated post. * Show photo count on Profile Pages on the "Photos" tab. * Revise the mobile and tablet top nav bar: * Always show small badge icons linking to the Site Gallery & Forum * Always show Friends & Messages badges. If no new notifications, they display as grey instead of yellow w/ a number. * Put icons next to most nav bar items, especially the User Menu * Tighten the sprawling page layouts in the Forums to be more compact for mobile screens. * Fix bug where some pages scrolled horizontally on mobile: the root cause was divs with class="content p-2", needs minimum p-3 (but p-4 is used) to provide enough padding to overcome column margins which were pushing the page too wide on mobile.
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package account
|
|
|
|
import (
|
|
"net/http"
|
|
"regexp"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/models"
|
|
"git.kirsle.net/apps/gosocial/pkg/session"
|
|
"git.kirsle.net/apps/gosocial/pkg/templates"
|
|
)
|
|
|
|
var ProfileRegexp = regexp.MustCompile(`^/u/([^@]+?)$`)
|
|
|
|
// User profile page (/u/username)
|
|
func Profile() http.HandlerFunc {
|
|
tmpl := templates.Must("account/profile.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Parse the username out of the URL parameters.
|
|
var username string
|
|
m := ProfileRegexp.FindStringSubmatch(r.URL.Path)
|
|
if m != nil {
|
|
username = m[1]
|
|
}
|
|
|
|
// Get the current user.
|
|
currentUser, err := session.CurrentUser(r)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't get CurrentUser: %s", err)
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
// Find this user.
|
|
user, err := models.FindUser(username)
|
|
if err != nil {
|
|
templates.NotFoundPage(w, r)
|
|
return
|
|
}
|
|
|
|
var isSelf = currentUser.ID == user.ID
|
|
|
|
// Banned or disabled? Only admin can view then.
|
|
if user.Status != models.UserStatusActive && !currentUser.IsAdmin {
|
|
templates.NotFoundPage(w, r)
|
|
return
|
|
}
|
|
|
|
// Is either one blocking?
|
|
if models.IsBlocking(currentUser.ID, user.ID) && !currentUser.IsAdmin {
|
|
templates.NotFoundPage(w, r)
|
|
return
|
|
}
|
|
|
|
// Are they friends? And/or is this user private?
|
|
var (
|
|
isFriend = models.FriendStatus(currentUser.ID, user.ID)
|
|
isPrivate = !currentUser.IsAdmin && !isSelf && user.Visibility == models.UserVisibilityPrivate && isFriend != "approved"
|
|
)
|
|
|
|
// Get Likes for this profile.
|
|
likeMap := models.MapLikes(currentUser, "users", []uint64{user.ID})
|
|
|
|
vars := map[string]interface{}{
|
|
"User": user,
|
|
"LikeMap": likeMap,
|
|
"IsFriend": isFriend,
|
|
"IsPrivate": isPrivate,
|
|
"PhotoCount": models.CountPhotos(user.ID),
|
|
}
|
|
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|