Search users by "Liked"
This commit is contained in:
parent
72b6e2a616
commit
8754ed8592
|
@ -39,6 +39,7 @@ func Search() http.HandlerFunc {
|
||||||
maritalStatus = r.FormValue("marital_status")
|
maritalStatus = r.FormValue("marital_status")
|
||||||
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"
|
||||||
sort = r.FormValue("sort")
|
sort = r.FormValue("sort")
|
||||||
sortOK bool
|
sortOK bool
|
||||||
)
|
)
|
||||||
|
@ -110,6 +111,7 @@ func Search() http.HandlerFunc {
|
||||||
IsDisabled: isCertified == "disabled",
|
IsDisabled: isCertified == "disabled",
|
||||||
IsAdmin: isCertified == "admin",
|
IsAdmin: isCertified == "admin",
|
||||||
Friends: friendSearch,
|
Friends: friendSearch,
|
||||||
|
Liked: likedSearch,
|
||||||
AgeMin: ageMin,
|
AgeMin: ageMin,
|
||||||
AgeMax: ageMax,
|
AgeMax: ageMax,
|
||||||
}, pager)
|
}, pager)
|
||||||
|
@ -122,8 +124,16 @@ func Search() http.HandlerFunc {
|
||||||
|
|
||||||
// Collect usernames to map to chat online status.
|
// Collect usernames to map to chat online status.
|
||||||
var usernames = []string{}
|
var usernames = []string{}
|
||||||
|
var userIDs = []uint64{}
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
usernames = append(usernames, user.Username)
|
usernames = append(usernames, user.Username)
|
||||||
|
userIDs = append(userIDs, user.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// User IDs of these I have "Liked"
|
||||||
|
likedIDs, err := models.LikedIDs(currentUser, "users", userIDs)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("LikedIDs: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var vars = map[string]interface{}{
|
var vars = map[string]interface{}{
|
||||||
|
@ -142,6 +152,7 @@ func Search() http.HandlerFunc {
|
||||||
"AgeMin": ageMin,
|
"AgeMin": ageMin,
|
||||||
"AgeMax": ageMax,
|
"AgeMax": ageMax,
|
||||||
"FriendSearch": friendSearch,
|
"FriendSearch": friendSearch,
|
||||||
|
"LikedSearch": likedSearch,
|
||||||
"Sort": sort,
|
"Sort": sort,
|
||||||
|
|
||||||
// Photo counts mapped to users
|
// Photo counts mapped to users
|
||||||
|
@ -150,8 +161,9 @@ func Search() http.HandlerFunc {
|
||||||
// Map Shy Account badges for these results
|
// Map Shy Account badges for these results
|
||||||
"ShyMap": models.MapShyAccounts(users),
|
"ShyMap": models.MapShyAccounts(users),
|
||||||
|
|
||||||
// Map friendships to these users.
|
// Map friendships and likes to these users.
|
||||||
"FriendMap": models.MapFriends(currentUser, users),
|
"FriendMap": models.MapFriends(currentUser, users),
|
||||||
|
"LikedMap": models.MapLikes(currentUser, "users", likedIDs),
|
||||||
|
|
||||||
// Users on the chat room map.
|
// Users on the chat room map.
|
||||||
"UserOnChatMap": worker.GetChatStatistics().MapUsersOnline(usernames),
|
"UserOnChatMap": worker.GetChatStatistics().MapUsersOnline(usernames),
|
||||||
|
|
|
@ -127,7 +127,6 @@ func Likes() http.HandlerFunc {
|
||||||
log.Error("subject is users, find %d", tableID)
|
log.Error("subject is users, find %d", tableID)
|
||||||
if user, err := models.GetUser(tableID); err == nil {
|
if user, err := models.GetUser(tableID); err == nil {
|
||||||
targetUser = user
|
targetUser = user
|
||||||
log.Warn("found user %s", targetUser.Username)
|
|
||||||
|
|
||||||
// Blocking safety check: if either user blocks the other, liking is not allowed.
|
// Blocking safety check: if either user blocks the other, liking is not allowed.
|
||||||
if models.IsBlocking(currentUser.ID, user.ID) {
|
if models.IsBlocking(currentUser.ID, user.ID) {
|
||||||
|
|
|
@ -267,6 +267,7 @@ type UserSearch struct {
|
||||||
IsDisabled bool
|
IsDisabled bool
|
||||||
IsAdmin bool // search for admin users
|
IsAdmin bool // search for admin users
|
||||||
Friends bool
|
Friends bool
|
||||||
|
Liked bool
|
||||||
AgeMin int
|
AgeMin int
|
||||||
AgeMax int
|
AgeMax int
|
||||||
}
|
}
|
||||||
|
@ -451,6 +452,20 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if search.Liked {
|
||||||
|
wheres = append(wheres, `
|
||||||
|
EXISTS (
|
||||||
|
SELECT 1 FROM likes
|
||||||
|
WHERE user_id = ?
|
||||||
|
AND table_name = 'users'
|
||||||
|
AND table_id = users.id
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
placeholders = append(placeholders,
|
||||||
|
user.ID,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if search.AgeMin > 0 {
|
if search.AgeMin > 0 {
|
||||||
date := time.Now().AddDate(-search.AgeMin, 0, 0)
|
date := time.Now().AddDate(-search.AgeMin, 0, 0)
|
||||||
wheres = append(wheres, `
|
wheres = append(wheres, `
|
||||||
|
|
18
web/static/js/slim-forms.js
Normal file
18
web/static/js/slim-forms.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* Slim "GET" forms: an onSubmit handler that trims empty query parameters. */
|
||||||
|
document.addEventListener('DOMContentLoaded', (e) => {
|
||||||
|
(document.querySelectorAll("form") || []).forEach(form => {
|
||||||
|
|
||||||
|
// Find forms with method="GET"
|
||||||
|
let method = form.method || "GET";
|
||||||
|
if (method.toUpperCase() !== "GET") {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Trim their empty parameters.
|
||||||
|
form.addEventListener("submit", (e) => {
|
||||||
|
for (let member of form.elements) {
|
||||||
|
if (!member.value) member.disabled = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
|
@ -230,7 +230,7 @@
|
||||||
|
|
||||||
<div class="column px-1">
|
<div class="column px-1">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="friends">Friendship:</label>
|
<label class="label" for="friends">Miscellanous:</label>
|
||||||
<label class="checkbox">
|
<label class="checkbox">
|
||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
name="friends"
|
name="friends"
|
||||||
|
@ -239,6 +239,14 @@
|
||||||
{{if .FriendSearch}}checked{{end}}>
|
{{if .FriendSearch}}checked{{end}}>
|
||||||
Show only my friends
|
Show only my friends
|
||||||
</label>
|
</label>
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox"
|
||||||
|
name="liked"
|
||||||
|
id="liked"
|
||||||
|
value="true"
|
||||||
|
{{if .LikedSearch}}checked{{end}}>
|
||||||
|
Show only my "Likes"
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -287,13 +295,24 @@
|
||||||
|
|
||||||
<!-- Friendship badge -->
|
<!-- Friendship badge -->
|
||||||
{{if $Root.FriendMap.Get .ID}}
|
{{if $Root.FriendMap.Get .ID}}
|
||||||
<div class="has-text-centered">
|
<div>
|
||||||
<span class="is-size-7 has-text-warning">
|
<span class="is-size-7 has-text-warning">
|
||||||
<i class="fa fa-user-group" title="Friends"></i>
|
<i class="fa fa-user-group" title="Friends"></i>
|
||||||
Friends
|
Friends
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
<!-- Liked badge -->
|
||||||
|
{{$LikedStats := $Root.LikedMap.Get .ID}}
|
||||||
|
{{if $LikedStats.UserLikes}}
|
||||||
|
<div>
|
||||||
|
<span class="is-size-7">
|
||||||
|
<i class="fa fa-user-group has-text-danger" title="Friends"></i>
|
||||||
|
Liked
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="media-content">
|
<div class="media-content">
|
||||||
<p class="title is-4">
|
<p class="title is-4">
|
||||||
|
|
|
@ -386,6 +386,7 @@
|
||||||
<script type="text/javascript" src="/static/js/likes.js?build={{.BuildHash}}"></script>
|
<script type="text/javascript" src="/static/js/likes.js?build={{.BuildHash}}"></script>
|
||||||
<script type="text/javascript" src="/static/js/vue-3.2.45.js"></script>
|
<script type="text/javascript" src="/static/js/vue-3.2.45.js"></script>
|
||||||
<script type="text/javascript" src="/static/js/htmx-1.9.12.min.js"></script>
|
<script type="text/javascript" src="/static/js/htmx-1.9.12.min.js"></script>
|
||||||
|
<script type="text/javascript" src="/static/js/slim-forms.js?build={{.BuildHash}}"></script>
|
||||||
{{template "scripts" .}}
|
{{template "scripts" .}}
|
||||||
|
|
||||||
<!-- Likes modal -->
|
<!-- Likes modal -->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user