From a6866bd12987152536ba06d50b8ba9475487c1a3 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 6 Aug 2023 21:06:27 -0700 Subject: [PATCH] Order the Who List by Logged-in Time --- pkg/handlers.go | 2 ++ pkg/messages.go | 1 + pkg/websocket.go | 2 ++ web/static/js/BareRTC.js | 5 +++++ web/templates/chat.html | 3 ++- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/handlers.go b/pkg/handlers.go index ff28f4e..ecec39f 100644 --- a/pkg/handlers.go +++ b/pkg/handlers.go @@ -5,6 +5,7 @@ import ( "fmt" "path/filepath" "strings" + "time" "git.kirsle.net/apps/barertc/pkg/config" "git.kirsle.net/apps/barertc/pkg/jwt" @@ -87,6 +88,7 @@ func (s *Server) OnLogin(sub *Subscriber, msg Message) { // Use their username. sub.Username = msg.Username sub.authenticated = true + sub.loginAt = time.Now() log.Debug("OnLogin: %s joins the room", sub.Username) // Tell everyone they joined. diff --git a/pkg/messages.go b/pkg/messages.go index deca2af..bdfdfe5 100644 --- a/pkg/messages.go +++ b/pkg/messages.go @@ -81,6 +81,7 @@ type WhoList struct { Nickname string `json:"nickname,omitempty"` Status string `json:"status"` Video int `json:"video"` + LoginAt int64 `json:"loginAt"` // JWT auth extra settings. Operator bool `json:"op"` diff --git a/pkg/websocket.go b/pkg/websocket.go index 95e28c4..0ec34ca 100644 --- a/pkg/websocket.go +++ b/pkg/websocket.go @@ -27,6 +27,7 @@ type Subscriber struct { VideoStatus int JWTClaims *jwt.Claims authenticated bool // has passed the login step + loginAt time.Time conn *websocket.Conn ctx context.Context cancel context.CancelFunc @@ -395,6 +396,7 @@ func (s *Server) SendWhoList() { Username: user.Username, Status: user.ChatStatus, Video: user.VideoStatus, + LoginAt: user.loginAt.Unix(), } // If this person had booted us, force their camera to "off" diff --git a/web/static/js/BareRTC.js b/web/static/js/BareRTC.js index cd1d28d..7298109 100644 --- a/web/static/js/BareRTC.js +++ b/web/static/js/BareRTC.js @@ -438,6 +438,11 @@ const app = Vue.createApp({ return a.emoji < b.emoji ? -1 : 1; }) break; + case "login": + result.sort((a, b) => { + return b.loginAt - a.loginAt; + }); + break; case "gender": result.sort((a, b) => { if (a.gender === b.gender) return 0; diff --git a/web/templates/chat.html b/web/templates/chat.html index bf191be..16022d9 100644 --- a/web/templates/chat.html +++ b/web/templates/chat.html @@ -987,12 +987,13 @@