mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 20:45:57 +08:00
msggateway refactor
This commit is contained in:
@@ -9,24 +9,24 @@ type UserMap struct {
|
||||
func newUserMap() *UserMap {
|
||||
return &UserMap{}
|
||||
}
|
||||
func (u *UserMap) GetAll(key string) []*Client {
|
||||
func (u *UserMap) GetAll(key string) ([]*Client, bool) {
|
||||
allClients, ok := u.m.Load(key)
|
||||
if ok {
|
||||
return allClients.([]*Client)
|
||||
return allClients.([]*Client), ok
|
||||
}
|
||||
return nil
|
||||
return nil, ok
|
||||
}
|
||||
func (u *UserMap) Get(key string, platformID int32) (*Client, bool) {
|
||||
allClients, existed := u.m.Load(key)
|
||||
if existed {
|
||||
func (u *UserMap) Get(key string, platformID int) (*Client, bool, bool) {
|
||||
allClients, userExisted := u.m.Load(key)
|
||||
if userExisted {
|
||||
for _, client := range allClients.([]*Client) {
|
||||
if client.PlatformID == platformID {
|
||||
return client, existed
|
||||
if client.platformID == platformID {
|
||||
return client, userExisted, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
return nil, userExisted, false
|
||||
}
|
||||
return nil, existed
|
||||
return nil, userExisted, false
|
||||
}
|
||||
func (u *UserMap) Set(key string, v *Client) {
|
||||
allClients, existed := u.m.Load(key)
|
||||
@@ -40,24 +40,25 @@ func (u *UserMap) Set(key string, v *Client) {
|
||||
u.m.Store(key, clients)
|
||||
}
|
||||
}
|
||||
func (u *UserMap) delete(key string, platformID int32) {
|
||||
func (u *UserMap) delete(key string, platformID int) (isDeleteUser bool) {
|
||||
allClients, existed := u.m.Load(key)
|
||||
if existed {
|
||||
oldClients := allClients.([]*Client)
|
||||
|
||||
a := make([]*Client, len(oldClients))
|
||||
a := make([]*Client, 3)
|
||||
for _, client := range oldClients {
|
||||
if client.PlatformID != platformID {
|
||||
if client.platformID != platformID {
|
||||
a = append(a, client)
|
||||
}
|
||||
}
|
||||
if len(a) == 0 {
|
||||
u.m.Delete(key)
|
||||
return true
|
||||
} else {
|
||||
u.m.Store(key, a)
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
return existed
|
||||
}
|
||||
func (u *UserMap) DeleteAll(key string) {
|
||||
u.m.Delete(key)
|
||||
|
||||
Reference in New Issue
Block a user