mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 12:36:00 +08:00
errcode
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package localcache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
@@ -27,12 +28,31 @@ func NewGroupMemberIDsLocalCache(rpc *grpc.ClientConn) GroupLocalCache {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) []string {
|
||||
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
resp, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
|
||||
GroupIDs: nil,
|
||||
GroupIDs: []string{groupID},
|
||||
})
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
return []string{}
|
||||
if len(resp.GroupAbstractInfos) < 0 {
|
||||
return nil, constant.ErrGroupIDNotFound
|
||||
}
|
||||
localHashInfo, ok := g.cache[groupID]
|
||||
if ok && localHashInfo.memberListHash == resp.GroupAbstractInfos[0].GroupMemberListHash {
|
||||
return localHashInfo.userIDs, nil
|
||||
}
|
||||
groupMembersResp, err := g.group.GetGroupMemberList(ctx, &group.GetGroupMemberListReq{
|
||||
GroupID: groupID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
g.cache[groupID] = GroupMemberIDsHash{
|
||||
memberListHash: resp.GroupAbstractInfos[0].GroupMemberListHash,
|
||||
userIDs: groupMembersResp.Members,
|
||||
}
|
||||
return g.cache[groupID].userIDs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user