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

71 lines
2.2 KiB

3 years ago
package group
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/table/relation"
3 years ago
pbGroup "Open_IM/pkg/proto/group"
sdk_ws "Open_IM/pkg/proto/sdk_ws"
3 years ago
"Open_IM/pkg/utils"
"context"
)
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
resp := &pbGroup.GetJoinedSuperGroupListResp{}
2 years ago
total, groupIDs, err := s.GroupInterface.FindJoinSuperGroup(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
3 years ago
if err != nil {
return nil, err
}
resp.Total = total
if len(groupIDs) == 0 {
3 years ago
return resp, nil
}
2 years ago
numMap, err := s.GroupInterface.MapSuperGroupMemberNum(ctx, groupIDs)
if err != nil {
return nil, err
}
2 years ago
owners, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
2 years ago
ownerMap := utils.SliceToMap(owners, func(e *relation.GroupMemberModel) string {
return e.GroupID
})
2 years ago
groups, err := s.GroupInterface.FindGroup(ctx, groupIDs)
if err != nil {
return nil, err
3 years ago
}
groupMap := utils.SliceToMap(groups, func(e *relation.GroupModel) string {
return e.GroupID
})
resp.Groups = utils.Slice(groupIDs, func(groupID string) *sdk_ws.GroupInfo {
2 years ago
return DbToPbGroupInfo(groupMap[groupID], ownerMap[groupID].UserID, numMap[groupID])
})
3 years ago
return resp, nil
}
3 years ago
2 years ago
func (s *groupServer) GetSuperGroupsInfo(ctx context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
resp = &pbGroup.GetSuperGroupsInfoResp{}
if len(req.GroupIDs) == 0 {
return nil, constant.ErrArgs.Wrap("groupIDs empty")
}
2 years ago
groups, err := s.GroupInterface.FindGroup(ctx, req.GroupIDs)
if err != nil {
return nil, err
}
2 years ago
numMap, err := s.GroupInterface.MapSuperGroupMemberNum(ctx, req.GroupIDs)
if err != nil {
return nil, err
}
2 years ago
owners, err := s.GroupInterface.FindGroupMember(ctx, req.GroupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
3 years ago
}
2 years ago
ownerMap := utils.SliceToMap(owners, func(e *relation.GroupMemberModel) string {
return e.GroupID
})
resp.GroupInfos = utils.Slice(groups, func(e *relation.GroupModel) *sdk_ws.GroupInfo {
2 years ago
return DbToPbGroupInfo(e, ownerMap[e.GroupID].UserID, numMap[e.GroupID])
})
3 years ago
return resp, nil
}