diff --git a/internal/msggateway/user_map.go b/internal/msggateway/user_map.go index ffaff75d9..3c00b8805 100644 --- a/internal/msggateway/user_map.go +++ b/internal/msggateway/user_map.go @@ -16,9 +16,10 @@ package msggateway import ( "context" - "github.com/openimsdk/tools/utils/datautil" "sync" + "github.com/openimsdk/tools/utils/datautil" + "github.com/openimsdk/tools/log" ) @@ -55,6 +56,7 @@ func (u *UserMap) Get(key string, platformID int) ([]*Client, bool, bool) { return nil, userExisted, false } +// Set adds a client to the map. func (u *UserMap) Set(key string, v *Client) { allClients, existed := u.m.Load(key) if existed { @@ -62,13 +64,12 @@ func (u *UserMap) Set(key string, v *Client) { oldClients := allClients.([]*Client) oldClients = append(oldClients, v) 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) {