From b52d9df958aa72cade7d53e493e937a63f2b7d17 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 19 Oct 2024 13:07:17 -0700 Subject: [PATCH] Member Search: Add a filter for "Currently on chat" --- pkg/controller/account/search.go | 15 +++++++++++++++ pkg/models/user.go | 8 +++++++- web/templates/account/search.html | 10 +++++++++- web/templates/chat.html | 5 +++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/controller/account/search.go b/pkg/controller/account/search.go index 9a83d9f..229ff33 100644 --- a/pkg/controller/account/search.go +++ b/pkg/controller/account/search.go @@ -6,6 +6,7 @@ import ( "strconv" "code.nonshy.com/nonshy/website/pkg/config" + "code.nonshy.com/nonshy/website/pkg/controller/chat" "code.nonshy.com/nonshy/website/pkg/geoip" "code.nonshy.com/nonshy/website/pkg/log" "code.nonshy.com/nonshy/website/pkg/models" @@ -44,6 +45,7 @@ func Search() http.HandlerFunc { hereFor = r.FormValue("here_for") friendSearch = r.FormValue("friends") == "true" likedSearch = r.FormValue("liked") == "true" + onChatSearch = r.FormValue("on_chat") == "true" sort = r.FormValue("sort") sortOK bool ) @@ -149,6 +151,17 @@ func Search() http.HandlerFunc { certifiedOnly = true } + // Are we filtering for "On Chat?" + var inUsername = []string{} + if onChatSearch { + stats := chat.FilteredChatStatistics(currentUser) + inUsername = stats.Usernames + if len(inUsername) == 0 { + session.FlashError(w, r, "Notice: you wanted to filter by people currently on the chat room, but nobody is on chat at this time.") + inUsername = []string{"@"} + } + } + pager := &models.Pagination{ PerPage: config.PageSizeMemberSearch, Sort: sort, @@ -157,6 +170,7 @@ func Search() http.HandlerFunc { users, err := models.SearchUsers(currentUser, &models.UserSearch{ Username: username, + InUsername: inUsername, Gender: gender, Orientation: orientation, MaritalStatus: maritalStatus, @@ -213,6 +227,7 @@ func Search() http.HandlerFunc { "AgeMax": ageMax, "FriendSearch": friendSearch, "LikedSearch": likedSearch, + "OnChatSearch": onChatSearch, "Sort": sort, // Restricted Search errors. diff --git a/pkg/models/user.go b/pkg/models/user.go index 7f4bf2f..e36fd26 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -291,7 +291,8 @@ func (u *User) CanBeSeenBy(viewer *User) error { // UserSearch config. type UserSearch struct { - Username string + Username string // fuzzy search by name or username + InUsername []string // exact set of usernames (e.g. On Chat) Gender string Orientation string MaritalStatus string @@ -373,6 +374,11 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er placeholders = append(placeholders, ilike, ilike) } + if len(search.InUsername) > 0 { + wheres = append(wheres, "users.username IN ?") + placeholders = append(placeholders, search.InUsername) + } + if search.Gender != "" { wheres = append(wheres, ` EXISTS ( diff --git a/web/templates/account/search.html b/web/templates/account/search.html index 7612f1c..f1423be 100644 --- a/web/templates/account/search.html +++ b/web/templates/account/search.html @@ -184,7 +184,7 @@
- + Show only my "Likes" +
diff --git a/web/templates/chat.html b/web/templates/chat.html index 8251328..3d2172d 100644 --- a/web/templates/chat.html +++ b/web/templates/chat.html @@ -106,6 +106,11 @@ 0). + + +
+ New: you can now search for who's on chat in the member directory! +

Chat Room Rules