Member Search: Add a filter for "Currently on chat"

This commit is contained in:
Noah Petherbridge 2024-10-19 13:07:17 -07:00
parent 1b3e8cb250
commit b52d9df958
4 changed files with 36 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"strconv" "strconv"
"code.nonshy.com/nonshy/website/pkg/config" "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/geoip"
"code.nonshy.com/nonshy/website/pkg/log" "code.nonshy.com/nonshy/website/pkg/log"
"code.nonshy.com/nonshy/website/pkg/models" "code.nonshy.com/nonshy/website/pkg/models"
@ -44,6 +45,7 @@ func Search() http.HandlerFunc {
hereFor = r.FormValue("here_for") hereFor = r.FormValue("here_for")
friendSearch = r.FormValue("friends") == "true" friendSearch = r.FormValue("friends") == "true"
likedSearch = r.FormValue("liked") == "true" likedSearch = r.FormValue("liked") == "true"
onChatSearch = r.FormValue("on_chat") == "true"
sort = r.FormValue("sort") sort = r.FormValue("sort")
sortOK bool sortOK bool
) )
@ -149,6 +151,17 @@ func Search() http.HandlerFunc {
certifiedOnly = true 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{ pager := &models.Pagination{
PerPage: config.PageSizeMemberSearch, PerPage: config.PageSizeMemberSearch,
Sort: sort, Sort: sort,
@ -157,6 +170,7 @@ func Search() http.HandlerFunc {
users, err := models.SearchUsers(currentUser, &models.UserSearch{ users, err := models.SearchUsers(currentUser, &models.UserSearch{
Username: username, Username: username,
InUsername: inUsername,
Gender: gender, Gender: gender,
Orientation: orientation, Orientation: orientation,
MaritalStatus: maritalStatus, MaritalStatus: maritalStatus,
@ -213,6 +227,7 @@ func Search() http.HandlerFunc {
"AgeMax": ageMax, "AgeMax": ageMax,
"FriendSearch": friendSearch, "FriendSearch": friendSearch,
"LikedSearch": likedSearch, "LikedSearch": likedSearch,
"OnChatSearch": onChatSearch,
"Sort": sort, "Sort": sort,
// Restricted Search errors. // Restricted Search errors.

View File

@ -291,7 +291,8 @@ func (u *User) CanBeSeenBy(viewer *User) error {
// UserSearch config. // UserSearch config.
type UserSearch struct { 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 Gender string
Orientation string Orientation string
MaritalStatus string MaritalStatus string
@ -373,6 +374,11 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er
placeholders = append(placeholders, ilike, ilike) placeholders = append(placeholders, ilike, ilike)
} }
if len(search.InUsername) > 0 {
wheres = append(wheres, "users.username IN ?")
placeholders = append(placeholders, search.InUsername)
}
if search.Gender != "" { if search.Gender != "" {
wheres = append(wheres, ` wheres = append(wheres, `
EXISTS ( EXISTS (

View File

@ -184,7 +184,7 @@
<div class="column pl-1"> <div class="column pl-1">
<div class="field"> <div class="field">
<label class="label" for="wcs">Location: <span class="tag is-success">New!</span></label> <label class="label" for="wcs">Location:</label>
<input type="text" class="input" <input type="text" class="input"
name="wcs" id="wcs" name="wcs" id="wcs"
autocomplete="off" autocomplete="off"
@ -301,6 +301,14 @@
{{if .LikedSearch}}checked{{end}}> {{if .LikedSearch}}checked{{end}}>
Show only my "Likes" Show only my "Likes"
</label> </label>
<label class="checkbox">
<input type="checkbox"
name="on_chat"
id="on_chat"
value="true"
{{if .OnChatSearch}}checked{{end}}>
Currently on chat <span class="tag is-success">New!</span>
</label>
</div> </div>
</div> </div>

View File

@ -106,6 +106,11 @@
<i class="fa fa-video has-text-danger"></i> <span id="cameraRed" class="has-text-danger">0</span>). <i class="fa fa-video has-text-danger"></i> <span id="cameraRed" class="has-text-danger">0</span>).
</span> </span>
</div> </div>
<!-- Link to the search page if people are online -->
<div class="mt-2">
<strong>New:</strong> you can now search for <a href="/members?on_chat=true">who's on chat</a> in the member directory!
</div>
</div> </div>
<h3>Chat Room Rules</h3> <h3>Chat Room Rules</h3>