0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 21:23:01 -05:00
safetwitch-backend/extractor/chat/chatRelayClientSorter.go
2023-06-08 07:50:34 -04:00

49 lines
805 B
Go

package chat
import (
"sync"
)
type ClientMap struct {
Clients map[*Client]bool
sync.Mutex
}
var ClientHandler = ClientMap{
Clients: map[*Client]bool{},
Mutex: sync.Mutex{},
}
func (c *ClientMap) AddClient(client *Client) {
c.Lock()
c.Clients[client] = true
c.Unlock()
}
func (c *ClientMap) DeleteClient(ID string) {
c.Lock()
for client := range c.Clients {
if client.ID == ID {
delete(c.Clients, client)
}
}
c.Unlock()
}
func (c *ClientMap) FindClientsByStreamer(streamer string) []*Client {
c.Lock()
var clients []*Client
for client := range c.Clients {
// check if the client is following the given streamer
for s, _ := range client.FollowingStreamers {
if s == streamer {
clients = append(clients, client)
break
}
}
}
c.Unlock()
return clients
}