mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-07 19:50:07 +08:00
realization group rpc
This commit is contained in:
parent
4645eec8b6
commit
26794503c3
@ -190,24 +190,24 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
var groupMembers []*relation2.GroupMemberModel
|
var groupMembers []*relation2.GroupMemberModel
|
||||||
utils.CopyStructFields(&group, req.GroupInfo)
|
utils.CopyStructFields(&group, req.GroupInfo)
|
||||||
group.GroupID = genGroupID(ctx, req.GroupInfo.GroupID)
|
group.GroupID = genGroupID(ctx, req.GroupInfo.GroupID)
|
||||||
|
joinGroup := func(userID string, roleLevel int32) error {
|
||||||
|
user := userMap[userID]
|
||||||
|
groupMember := &relation2.GroupMemberModel{GroupID: group.GroupID, RoleLevel: roleLevel, OperatorUserID: tracelog.GetOpUserID(ctx), JoinSource: constant.JoinByInvitation, InviterUserID: tracelog.GetOpUserID(ctx)}
|
||||||
|
utils.CopyStructFields(&groupMember, user)
|
||||||
|
if err := CallbackBeforeMemberJoinGroup(ctx, tracelog.GetOperationID(ctx), groupMember, group.Ex); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
groupMembers = append(groupMembers, groupMember)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := joinGroup(req.OwnerUserID, constant.GroupOwner); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if req.GroupInfo.GroupType == constant.SuperGroup {
|
if req.GroupInfo.GroupType == constant.SuperGroup {
|
||||||
if err := s.GroupInterface.CreateSuperGroup(ctx, group.GroupID, userIDs); err != nil {
|
if err := s.GroupInterface.CreateSuperGroup(ctx, group.GroupID, userIDs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
joinGroup := func(userID string, roleLevel int32) error {
|
|
||||||
user := userMap[userID]
|
|
||||||
groupMember := &relation2.GroupMemberModel{GroupID: group.GroupID, RoleLevel: roleLevel, OperatorUserID: tracelog.GetOpUserID(ctx), JoinSource: constant.JoinByInvitation, InviterUserID: tracelog.GetOpUserID(ctx)}
|
|
||||||
utils.CopyStructFields(&groupMember, user)
|
|
||||||
if err := CallbackBeforeMemberJoinGroup(ctx, tracelog.GetOperationID(ctx), groupMember, group.Ex); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
groupMembers = append(groupMembers, groupMember)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := joinGroup(req.OwnerUserID, constant.GroupOwner); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, userID := range req.AdminUserIDs {
|
for _, userID := range req.AdminUserIDs {
|
||||||
if err := joinGroup(userID, constant.GroupAdmin); err != nil {
|
if err := joinGroup(userID, constant.GroupAdmin); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,68 +1,64 @@
|
|||||||
package group
|
package group
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/db/table/relation"
|
||||||
cp "Open_IM/pkg/common/utils"
|
|
||||||
pbGroup "Open_IM/pkg/proto/group"
|
pbGroup "Open_IM/pkg/proto/group"
|
||||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
|
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
resp := &pbGroup.GetJoinedSuperGroupListResp{}
|
||||||
resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &commonPb.CommonResp{}}
|
total, groupIDs, err := s.GroupInterface.GetJoinSuperGroupByID(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||||
groupIDList, err := rocksCache.GetJoinedSuperGroupListFromCache(ctx, req.UserID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == redis.Nil {
|
return nil, err
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID nil ", err.Error(), req.UserID)
|
}
|
||||||
return resp, nil
|
resp.Total = total
|
||||||
}
|
if len(groupIDs) == 0 {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID failed ", err.Error(), req.UserID)
|
|
||||||
//resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
||||||
//resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
for _, groupID := range groupIDList {
|
numMap, err := s.GroupInterface.GetSuperGroupMemberNum(ctx, groupIDs)
|
||||||
groupInfoFromCache, err := rocksCache.GetGroupInfoFromCache(ctx, groupID)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupInfoByGroupID failed", groupID, err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
groupInfo := &commonPb.GroupInfo{}
|
|
||||||
if err := utils.CopyStructFields(groupInfo, groupInfoFromCache); err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
|
||||||
}
|
|
||||||
groupMemberIDList, err := rocksCache.GetGroupMemberIDListFromCache(ctx, groupID)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroup failed", groupID, err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
groupInfo.MemberCount = uint32(len(groupMemberIDList))
|
|
||||||
resp.GroupList = append(resp.GroupList, groupInfo)
|
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
ownerIdMap, err := s.GroupInterface.GetGroupOwnerUserID(ctx, groupIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
groups, err := s.GroupInterface.FindGroupsByID(ctx, groupIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
groupMap := utils.SliceToMap(groups, func(e *relation.GroupModel) string {
|
||||||
|
return e.GroupID
|
||||||
|
})
|
||||||
|
resp.Groups = utils.Slice(groupIDs, func(groupID string) *sdk_ws.GroupInfo {
|
||||||
|
return DbToPbGroupInfo(groupMap[groupID], ownerIdMap[groupID], numMap[groupID])
|
||||||
|
})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) GetSuperGroupsInfo(ctx context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
|
func (s *groupServer) GetSuperGroupsInfo(ctx context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
resp = &pbGroup.GetSuperGroupsInfoResp{}
|
||||||
resp = &pbGroup.GetSuperGroupsInfoResp{CommonResp: &commonPb.CommonResp{}}
|
if len(req.GroupIDs) == 0 {
|
||||||
groupsInfoList := make([]*commonPb.GroupInfo, 0)
|
return nil, constant.ErrArgs.Wrap("groupIDs empty")
|
||||||
for _, groupID := range req.GroupIDList {
|
|
||||||
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(ctx, groupID)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var groupInfo commonPb.GroupInfo
|
|
||||||
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromRedis)
|
|
||||||
groupsInfoList = append(groupsInfoList, &groupInfo)
|
|
||||||
}
|
}
|
||||||
resp.GroupInfoList = groupsInfoList
|
groups, err := s.GroupInterface.FindGroupsByID(ctx, req.GroupIDs)
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
numMap, err := s.GroupInterface.GetSuperGroupMemberNum(ctx, req.GroupIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ownerIdMap, err := s.GroupInterface.GetGroupOwnerUserID(ctx, req.GroupIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp.GroupInfos = utils.Slice(groups, func(e *relation.GroupModel) *sdk_ws.GroupInfo {
|
||||||
|
return DbToPbGroupInfo(e, ownerIdMap[e.GroupID], numMap[e.GroupID])
|
||||||
|
})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,8 @@ type GroupInterface interface {
|
|||||||
DelSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
DelSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||||
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||||
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
|
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
|
||||||
|
GetJoinSuperGroupByID(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
|
||||||
|
GetSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ GroupInterface = (*GroupController)(nil)
|
var _ GroupInterface = (*GroupController)(nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user