fix: fix get functions bug

pull/2100/head
Xinwei Xiong (cubxxw) 2 years ago
parent e554f33b7d
commit 3053d4a5ce

@ -16,9 +16,10 @@ package msggateway
import ( import (
"context" "context"
"github.com/openimsdk/tools/utils/datautil"
"sync" "sync"
"github.com/openimsdk/tools/utils/datautil"
"github.com/openimsdk/tools/log" "github.com/openimsdk/tools/log"
) )
@ -55,6 +56,7 @@ func (u *UserMap) Get(key string, platformID int) ([]*Client, bool, bool) {
return nil, userExisted, false return nil, userExisted, false
} }
// Set adds a client to the map.
func (u *UserMap) Set(key string, v *Client) { func (u *UserMap) Set(key string, v *Client) {
allClients, existed := u.m.Load(key) allClients, existed := u.m.Load(key)
if existed { if existed {
@ -62,13 +64,12 @@ func (u *UserMap) Set(key string, v *Client) {
oldClients := allClients.([]*Client) oldClients := allClients.([]*Client)
oldClients = append(oldClients, v) oldClients = append(oldClients, v)
u.m.Store(key, oldClients) u.m.Store(key, oldClients)
} else {
log.ZDebug(context.Background(), "Set not existed", "user_id", key, "client_user_id", v.UserID)
var clients []*Client
clients = append(clients, v)
u.m.Store(key, clients)
} }
log.ZDebug(context.Background(), "Set not existed", "user_id", key, "client_user_id", v.UserID)
var clients []*Client
clients = append(clients, v)
u.m.Store(key, clients)
} }
func (u *UserMap) delete(key string, connRemoteAddr string) (isDeleteUser bool) { func (u *UserMap) delete(key string, connRemoteAddr string) (isDeleteUser bool) {

Loading…
Cancel
Save