Expose connected client ID to moderator client info api
This commit is contained in:
parent
cdbb3b7a03
commit
3abc7a3ab8
@ -16,6 +16,7 @@ import (
|
||||
// GetUserDetails returns the details of a chat user for moderators.
|
||||
func GetUserDetails(w http.ResponseWriter, r *http.Request) {
|
||||
type connectedClient struct {
|
||||
Id uint `json:"id"`
|
||||
MessageCount int `json:"messageCount"`
|
||||
UserAgent string `json:"userAgent"`
|
||||
ConnectedAt time.Time `json:"connectedAt"`
|
||||
@ -42,6 +43,7 @@ func GetUserDetails(w http.ResponseWriter, r *http.Request) {
|
||||
clients := make([]connectedClient, len(c))
|
||||
for i, c := range c {
|
||||
client := connectedClient{
|
||||
Id: c.Id,
|
||||
MessageCount: c.MessageCount,
|
||||
UserAgent: c.UserAgent,
|
||||
ConnectedAt: c.ConnectedAt,
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
// Client represents a single chat client.
|
||||
type Client struct {
|
||||
mu sync.RWMutex
|
||||
id uint
|
||||
Id uint `json:"-"`
|
||||
accessToken string
|
||||
conn *websocket.Conn
|
||||
User *user.User `json:"user"`
|
||||
@ -123,7 +123,7 @@ func (c *Client) readPump() {
|
||||
|
||||
// Guard against floods.
|
||||
if !c.passesRateLimit() {
|
||||
log.Warnln("Client", c.id, c.User.DisplayName, "has exceeded the messaging rate limiting thresholds and messages are being rejected temporarily.")
|
||||
log.Warnln("Client", c.Id, c.User.DisplayName, "has exceeded the messaging rate limiting thresholds and messages are being rejected temporarily.")
|
||||
c.startChatRejectionTimeout()
|
||||
|
||||
continue
|
||||
@ -186,14 +186,14 @@ func (c *Client) handleEvent(data []byte) {
|
||||
}
|
||||
|
||||
func (c *Client) close() {
|
||||
log.Traceln("client closed:", c.User.DisplayName, c.id, c.IPAddress)
|
||||
log.Traceln("client closed:", c.User.DisplayName, c.Id, c.IPAddress)
|
||||
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
if c.send != nil {
|
||||
_ = c.conn.Close()
|
||||
c.server.unregister <- c.id
|
||||
c.server.unregister <- c.Id
|
||||
close(c.send)
|
||||
c.send = nil
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ func (s *Server) userNameChanged(eventData chatClientEvent) {
|
||||
|
||||
// Send chat user name changed webhook
|
||||
receivedEvent.User = savedUser
|
||||
receivedEvent.ClientID = eventData.client.id
|
||||
receivedEvent.ClientID = eventData.client.Id
|
||||
webhooks.SendChatEventUsernameChanged(receivedEvent)
|
||||
|
||||
// Resend the client's user so their username is in sync.
|
||||
@ -128,7 +128,7 @@ func (s *Server) userMessageSent(eventData chatClientEvent) {
|
||||
}
|
||||
|
||||
event.SetDefaults()
|
||||
event.ClientID = eventData.client.id
|
||||
event.ClientID = eventData.client.Id
|
||||
|
||||
// Ignore empty messages
|
||||
if event.Empty() {
|
||||
|
@ -99,14 +99,14 @@ func (s *Server) Addclient(conn *websocket.Conn, user *user.User, accessToken st
|
||||
|
||||
s.mu.Lock()
|
||||
{
|
||||
client.id = s.seq
|
||||
s.clients[client.id] = client
|
||||
client.Id = s.seq
|
||||
s.clients[client.Id] = client
|
||||
s.seq++
|
||||
_lastSeenCache[user.ID] = time.Now()
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
log.Traceln("Adding client", client.id, "total count:", len(s.clients))
|
||||
log.Traceln("Adding client", client.Id, "total count:", len(s.clients))
|
||||
|
||||
go client.writePump()
|
||||
go client.readPump()
|
||||
@ -132,7 +132,7 @@ func (s *Server) sendUserJoinedMessage(c *Client) {
|
||||
userJoinedEvent := events.UserJoinedEvent{}
|
||||
userJoinedEvent.SetDefaults()
|
||||
userJoinedEvent.User = c.User
|
||||
userJoinedEvent.ClientID = c.id
|
||||
userJoinedEvent.ClientID = c.Id
|
||||
|
||||
if err := s.Broadcast(userJoinedEvent.GetBroadcastPayload()); err != nil {
|
||||
log.Errorln("error adding client to chat server", err)
|
||||
@ -148,9 +148,9 @@ func (s *Server) ClientClosed(c *Client) {
|
||||
defer s.mu.Unlock()
|
||||
c.close()
|
||||
|
||||
if _, ok := s.clients[c.id]; ok {
|
||||
log.Debugln("Deleting", c.id)
|
||||
delete(s.clients, c.id)
|
||||
if _, ok := s.clients[c.Id]; ok {
|
||||
log.Debugln("Deleting", c.Id)
|
||||
delete(s.clients, c.Id)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user