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"
"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.

View File

@ -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 (

View File

@ -184,7 +184,7 @@
<div class="column pl-1">
<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"
name="wcs" id="wcs"
autocomplete="off"
@ -301,6 +301,14 @@
{{if .LikedSearch}}checked{{end}}>
Show only my "Likes"
</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>

View File

@ -106,6 +106,11 @@
<i class="fa fa-video has-text-danger"></i> <span id="cameraRed" class="has-text-danger">0</span>).
</span>
</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>
<h3>Chat Room Rules</h3>