Show currently on chat indicators
This commit is contained in:
parent
5ceeeb5fee
commit
fdc6c5c0a7
|
@ -10,6 +10,7 @@ import (
|
||||||
"code.nonshy.com/nonshy/website/pkg/models"
|
"code.nonshy.com/nonshy/website/pkg/models"
|
||||||
"code.nonshy.com/nonshy/website/pkg/session"
|
"code.nonshy.com/nonshy/website/pkg/session"
|
||||||
"code.nonshy.com/nonshy/website/pkg/templates"
|
"code.nonshy.com/nonshy/website/pkg/templates"
|
||||||
|
"code.nonshy.com/nonshy/website/pkg/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ProfileRegexp = regexp.MustCompile(`^/u/([^@]+?)$`)
|
var ProfileRegexp = regexp.MustCompile(`^/u/([^@]+?)$`)
|
||||||
|
@ -118,6 +119,7 @@ func Profile() http.HandlerFunc {
|
||||||
"IsFriend": isFriend,
|
"IsFriend": isFriend,
|
||||||
"IsPrivate": isPrivate,
|
"IsPrivate": isPrivate,
|
||||||
"PhotoCount": models.CountPhotosICanSee(user, currentUser),
|
"PhotoCount": models.CountPhotosICanSee(user, currentUser),
|
||||||
|
"OnChat": worker.GetChatStatistics().IsOnline(user.Username),
|
||||||
|
|
||||||
// Details on who likes the photo.
|
// Details on who likes the photo.
|
||||||
"LikeExample": likeExample,
|
"LikeExample": likeExample,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"code.nonshy.com/nonshy/website/pkg/models"
|
"code.nonshy.com/nonshy/website/pkg/models"
|
||||||
"code.nonshy.com/nonshy/website/pkg/session"
|
"code.nonshy.com/nonshy/website/pkg/session"
|
||||||
"code.nonshy.com/nonshy/website/pkg/templates"
|
"code.nonshy.com/nonshy/website/pkg/templates"
|
||||||
|
"code.nonshy.com/nonshy/website/pkg/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Search controller.
|
// Search controller.
|
||||||
|
@ -106,6 +107,12 @@ func Search() http.HandlerFunc {
|
||||||
// Who's Nearby feature, get some data.
|
// Who's Nearby feature, get some data.
|
||||||
insights, _ := geoip.GetRequestInsights(r)
|
insights, _ := geoip.GetRequestInsights(r)
|
||||||
|
|
||||||
|
// Collect usernames to map to chat online status.
|
||||||
|
var usernames = []string{}
|
||||||
|
for _, user := range users {
|
||||||
|
usernames = append(usernames, user.Username)
|
||||||
|
}
|
||||||
|
|
||||||
var vars = map[string]interface{}{
|
var vars = map[string]interface{}{
|
||||||
"Users": users,
|
"Users": users,
|
||||||
"Pager": pager,
|
"Pager": pager,
|
||||||
|
@ -132,6 +139,9 @@ func Search() http.HandlerFunc {
|
||||||
// Map friendships to these users.
|
// Map friendships to these users.
|
||||||
"FriendMap": models.MapFriends(currentUser, users),
|
"FriendMap": models.MapFriends(currentUser, users),
|
||||||
|
|
||||||
|
// Users on the chat room map.
|
||||||
|
"UserOnChatMap": worker.GetChatStatistics().MapUsersOnline(usernames),
|
||||||
|
|
||||||
// Current user's location setting.
|
// Current user's location setting.
|
||||||
"MyLocation": myLocation,
|
"MyLocation": myLocation,
|
||||||
"GeoIPInsights": insights,
|
"GeoIPInsights": insights,
|
||||||
|
|
|
@ -41,6 +41,32 @@ func SetChatStatistics(stats *ChatStatistics) {
|
||||||
cachedChatStatistics = stats
|
cachedChatStatistics = stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsOnline returns whether the username is currently logged-in to chat.
|
||||||
|
func (cs ChatStatistics) IsOnline(username string) bool {
|
||||||
|
for _, user := range cs.Usernames {
|
||||||
|
if user == username {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserOnChatMap map[string]bool
|
||||||
|
|
||||||
|
// MapUsersOnline returns a hashmap of usernames to online status.
|
||||||
|
func (cs ChatStatistics) MapUsersOnline(usernames []string) UserOnChatMap {
|
||||||
|
var result = UserOnChatMap{}
|
||||||
|
for _, user := range cs.Usernames {
|
||||||
|
result[user] = true
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a result from the UserOnChatMap.
|
||||||
|
func (m UserOnChatMap) Get(username string) bool {
|
||||||
|
return m[username]
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cachedChatStatistics *ChatStatistics
|
cachedChatStatistics *ChatStatistics
|
||||||
chatStatisticsMu sync.RWMutex
|
chatStatisticsMu sync.RWMutex
|
||||||
|
|
|
@ -68,6 +68,13 @@
|
||||||
{{SincePrettyCoarse .User.LastLoginAt}} ago
|
{{SincePrettyCoarse .User.LastLoginAt}} ago
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
{{if .OnChat}}
|
||||||
|
<div class="my-1">
|
||||||
|
<span class="tag is-success is-light">
|
||||||
|
<i class="fa fa-user mr-2"></i> Currently on chat!
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
{{if .User.Certified}}
|
{{if .User.Certified}}
|
||||||
<div class="pt-1">
|
<div class="pt-1">
|
||||||
<div class="icon-text" title="This user has been certified via a verification selfie.">
|
<div class="icon-text" title="This user has been certified via a verification selfie.">
|
||||||
|
|
|
@ -331,6 +331,16 @@
|
||||||
<span class="mr-2">{{.GetProfileField "orientation"}}</span>
|
<span class="mr-2">{{.GetProfileField "orientation"}}</span>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
<!-- Chat room status -->
|
||||||
|
{{if $Root.UserOnChatMap.Get .Username}}
|
||||||
|
<div>
|
||||||
|
<span class="tag is-success is-light">
|
||||||
|
<i class="fa fa-user mr-2"></i>
|
||||||
|
Currently on chat!
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
<!-- Show a subfooter based on ordered by -->
|
<!-- Show a subfooter based on ordered by -->
|
||||||
{{if eq $Root.Sort "last_login_at desc"}}
|
{{if eq $Root.Sort "last_login_at desc"}}
|
||||||
<div>
|
<div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user