You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/rpc/group/super_group.go

68 lines
2.8 KiB

3 years ago
package group
import (
rocksCache "Open_IM/pkg/common/db/rocks_cache"
3 years ago
"Open_IM/pkg/common/log"
3 years ago
cp "Open_IM/pkg/common/utils"
3 years ago
pbGroup "Open_IM/pkg/proto/group"
3 years ago
commonPb "Open_IM/pkg/proto/sdk_ws"
3 years ago
"Open_IM/pkg/utils"
"context"
2 years ago
"github.com/go-redis/redis/v8"
3 years ago
)
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
3 years ago
resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &pbGroup.CommonResp{}}
groupIDList, err := rocksCache.GetJoinedSuperGroupListFromCache(req.UserID)
3 years ago
if err != nil {
2 years ago
if err == redis.Nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID nil ", err.Error(), req.UserID)
return resp, nil
}
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID failed ", err.Error(), req.UserID)
2 years ago
//resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
//resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
3 years ago
return resp, nil
}
for _, groupID := range groupIDList {
groupInfoFromCache, err := rocksCache.GetGroupInfoFromCache(groupID)
3 years ago
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupInfoByGroupID failed", groupID, err.Error())
continue
}
groupInfo := &commonPb.GroupInfo{}
if err := utils.CopyStructFields(groupInfo, groupInfoFromCache); err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
groupMemberIDList, err := rocksCache.GetGroupMemberIDListFromCache(groupID)
3 years ago
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroup failed", groupID, err.Error())
continue
}
groupInfo.MemberCount = uint32(len(groupMemberIDList))
3 years ago
resp.GroupList = append(resp.GroupList, groupInfo)
}
2 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
3 years ago
return resp, nil
}
3 years ago
func (s *groupServer) GetSuperGroupsInfo(_ context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
3 years ago
resp = &pbGroup.GetSuperGroupsInfoResp{CommonResp: &pbGroup.CommonResp{}}
3 years ago
groupsInfoList := make([]*commonPb.GroupInfo, 0)
for _, groupID := range req.GroupIDList {
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(groupID)
3 years ago
if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
continue
}
var groupInfo commonPb.GroupInfo
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromRedis)
3 years ago
groupsInfoList = append(groupsInfoList, &groupInfo)
}
resp.GroupInfoList = groupsInfoList
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}