Site Gallery: Remember last 'Whose photos' preference

This commit is contained in:
Noah Petherbridge 2023-11-24 11:37:01 -08:00
parent f0373285eb
commit d72f0b1d2d
4 changed files with 11 additions and 1 deletions

View File

@ -69,6 +69,7 @@ var (
SitePreferenceFields = []string{ SitePreferenceFields = []string{
"dm_privacy", "dm_privacy",
"blur_explicit", "blur_explicit",
"site_gallery_default", // default view on site gallery (friends-only or all certified?)
} }
// Choices for the Contact Us subject // Choices for the Contact Us subject

View File

@ -60,6 +60,10 @@ func SiteGallery() http.HandlerFunc {
if viewStyle != "full" { if viewStyle != "full" {
viewStyle = "cards" viewStyle = "cards"
} }
if who == "" {
// They didn't post a "Whose photos" filter, restore it from their last saved default.
who = currentUser.GetProfileField("site_gallery_default")
}
if who != "friends" && who != "everybody" && who != "friends+private" { if who != "friends" && who != "everybody" && who != "friends+private" {
// Default Who setting should be Friends-only, unless you have no friends. // Default Who setting should be Friends-only, unless you have no friends.
if myFriendCount > 0 { if myFriendCount > 0 {
@ -69,6 +73,9 @@ func SiteGallery() http.HandlerFunc {
} }
} }
// Store their "Whose photos" filter on their page to default it for next time.
currentUser.SetProfileField("site_gallery_default", who)
// Admin scope warning. // Admin scope warning.
if adminView && !currentUser.HasAdminScope(config.ScopePhotoModerator) { if adminView && !currentUser.HasAdminScope(config.ScopePhotoModerator) {
session.FlashError(w, r, "Missing admin scope: %s", config.ScopePhotoModerator) session.FlashError(w, r, "Missing admin scope: %s", config.ScopePhotoModerator)

View File

@ -224,7 +224,6 @@ func MapLikes(user *User, tableName string, tableIDs []uint64) LikeMap {
// Does the CURRENT USER like any of these IDs? // Does the CURRENT USER like any of these IDs?
if likedIDs, err := LikedIDs(user, tableName, tableIDs); err == nil { if likedIDs, err := LikedIDs(user, tableName, tableIDs); err == nil {
log.Error("USER LIKES IDS: %+v", likedIDs)
for _, id := range likedIDs { for _, id := range likedIDs {
if stats, ok := result[id]; ok { if stats, ok := result[id]; ok {
stats.UserLikes = true stats.UserLikes = true

View File

@ -579,6 +579,9 @@ func (u *User) SetProfileField(name, value string) {
Name: name, Name: name,
Value: value, Value: value,
}) })
if err := u.Save(); err != nil {
log.Error("User(%s).SetProfileField(%s): error saving after append new field: %s", u.Username, name, err)
}
} }
// GetProfileField returns the value of a profile field or blank string. // GetProfileField returns the value of a profile field or blank string.