From 2f352f86649bb9ac6277c89b3a791a2e81291bab Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 27 Apr 2024 19:06:17 -0700 Subject: [PATCH] Ability to find your "Likes" on the Site Gallery --- pkg/controller/photo/site_gallery.go | 3 ++- pkg/models/photo.go | 15 +++++++++++++++ web/templates/photo/gallery.html | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/controller/photo/site_gallery.go b/pkg/controller/photo/site_gallery.go index d6c9c49..39a4963 100644 --- a/pkg/controller/photo/site_gallery.go +++ b/pkg/controller/photo/site_gallery.go @@ -64,7 +64,7 @@ func SiteGallery() http.HandlerFunc { // 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" && who != "likes" { // Default Who setting should be Friends-only, unless you have no friends. if myFriendCount > 0 { who = "friends" @@ -94,6 +94,7 @@ func SiteGallery() http.HandlerFunc { AdminView: adminView, FriendsOnly: who == "friends", IsShy: isShy || who == "friends+private", + MyLikes: who == "likes", }, pager) // Bulk load the users associated with these photos. diff --git a/pkg/models/photo.go b/pkg/models/photo.go index e36060f..bedc157 100644 --- a/pkg/models/photo.go +++ b/pkg/models/photo.go @@ -474,6 +474,7 @@ type Gallery struct { AdminView bool // Show all images IsShy bool // Current user is like a Shy Account (or: show self/friends and private photo grants only) FriendsOnly bool // Only show self/friends instead of everybody's pics + MyLikes bool // Filter to photos I have liked } /* @@ -577,6 +578,20 @@ func PaginateGalleryPhotos(user *User, conf Gallery, pager *Pagination) ([]*Phot wheres = append(wheres, "gallery = ?") placeholders = append(placeholders, true) + // Filter by photos the user has liked. + if conf.MyLikes { + wheres = append(wheres, ` + EXISTS ( + SELECT 1 + FROM likes + WHERE user_id = ? + AND table_name = 'photos' + AND table_id = photos.id + ) + `) + placeholders = append(placeholders, user.ID) + } + // Filter blocked users. if len(blocklist) > 0 { wheres = append(wheres, "user_id NOT IN ?") diff --git a/web/templates/photo/gallery.html b/web/templates/photo/gallery.html index 8af9e80..61b90aa 100644 --- a/web/templates/photo/gallery.html +++ b/web/templates/photo/gallery.html @@ -336,6 +336,10 @@ as any private photos shared with you by others on the site (if they are marked to appear in the Site Gallery). + {{else if eq .FilterWho "likes"}} +
+ Showing you photos that you have Liked. +
{{end}} @@ -365,6 +369,7 @@