forked from asternic/wuzapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclients.go
More file actions
86 lines (72 loc) · 1.99 KB
/
clients.go
File metadata and controls
86 lines (72 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"sync"
"github.com/go-resty/resty/v2"
"go.mau.fi/whatsmeow"
)
type ClientManager struct {
sync.RWMutex
whatsmeowClients map[string]*whatsmeow.Client
httpClients map[string]*resty.Client
myClients map[string]*MyClient
}
func NewClientManager() *ClientManager {
return &ClientManager{
whatsmeowClients: make(map[string]*whatsmeow.Client),
httpClients: make(map[string]*resty.Client),
myClients: make(map[string]*MyClient),
}
}
func (cm *ClientManager) SetWhatsmeowClient(userID string, client *whatsmeow.Client) {
cm.Lock()
defer cm.Unlock()
cm.whatsmeowClients[userID] = client
}
func (cm *ClientManager) GetWhatsmeowClient(userID string) *whatsmeow.Client {
cm.RLock()
defer cm.RUnlock()
return cm.whatsmeowClients[userID]
}
func (cm *ClientManager) DeleteWhatsmeowClient(userID string) {
cm.Lock()
defer cm.Unlock()
delete(cm.whatsmeowClients, userID)
}
func (cm *ClientManager) SetHTTPClient(userID string, client *resty.Client) {
cm.Lock()
defer cm.Unlock()
cm.httpClients[userID] = client
}
func (cm *ClientManager) GetHTTPClient(userID string) *resty.Client {
cm.RLock()
defer cm.RUnlock()
return cm.httpClients[userID]
}
func (cm *ClientManager) DeleteHTTPClient(userID string) {
cm.Lock()
defer cm.Unlock()
delete(cm.httpClients, userID)
}
func (cm *ClientManager) SetMyClient(userID string, client *MyClient) {
cm.Lock()
defer cm.Unlock()
cm.myClients[userID] = client
}
func (cm *ClientManager) GetMyClient(userID string) *MyClient {
cm.RLock()
defer cm.RUnlock()
return cm.myClients[userID]
}
func (cm *ClientManager) DeleteMyClient(userID string) {
cm.Lock()
defer cm.Unlock()
delete(cm.myClients, userID)
}
// UpdateMyClientSubscriptions updates the event subscriptions of a client without reconnecting
func (cm *ClientManager) UpdateMyClientSubscriptions(userID string, subscriptions []string) {
cm.Lock()
defer cm.Unlock()
if client, exists := cm.myClients[userID]; exists {
client.subscriptions = subscriptions
}
}