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