Files
open-im-server/internal/rpc/group/super_group.go
T

71 lines
2.2 KiB
Go
Raw Normal View History

2022-05-30 11:55:27 +08:00
package group
import (
2023-02-07 15:48:18 +08:00
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/table/relation"
2022-05-30 11:55:27 +08:00
pbGroup "Open_IM/pkg/proto/group"
2023-02-07 15:48:18 +08:00
sdk_ws "Open_IM/pkg/proto/sdk_ws"
2022-05-30 11:55:27 +08:00
"Open_IM/pkg/utils"
"context"
)
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
2023-02-07 15:48:18 +08:00
resp := &pbGroup.GetJoinedSuperGroupListResp{}
2023-02-07 17:16:04 +08:00
total, groupIDs, err := s.GroupInterface.FindJoinSuperGroup(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
2022-05-30 11:55:27 +08:00
if err != nil {
2023-02-07 15:48:18 +08:00
return nil, err
}
resp.Total = total
if len(groupIDs) == 0 {
2022-05-30 11:55:27 +08:00
return resp, nil
}
2023-02-07 17:16:04 +08:00
numMap, err := s.GroupInterface.MapSuperGroupMemberNum(ctx, groupIDs)
2023-02-07 15:48:18 +08:00
if err != nil {
return nil, err
}
2023-02-08 14:41:09 +08:00
owners, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
2023-02-07 15:48:18 +08:00
if err != nil {
return nil, err
}
2023-02-08 14:41:09 +08:00
ownerMap := utils.SliceToMap(owners, func(e *relation.GroupMemberModel) string {
return e.GroupID
})
2023-02-07 17:16:04 +08:00
groups, err := s.GroupInterface.FindGroup(ctx, groupIDs)
2023-02-07 15:48:18 +08:00
if err != nil {
return nil, err
2022-05-30 15:10:26 +08:00
}
2023-02-07 15:48:18 +08:00
groupMap := utils.SliceToMap(groups, func(e *relation.GroupModel) string {
return e.GroupID
})
resp.Groups = utils.Slice(groupIDs, func(groupID string) *sdk_ws.GroupInfo {
2023-02-08 14:41:09 +08:00
return DbToPbGroupInfo(groupMap[groupID], ownerMap[groupID].UserID, numMap[groupID])
2023-02-07 15:48:18 +08:00
})
2022-05-30 11:55:27 +08:00
return resp, nil
}
2022-05-30 16:23:15 +08:00
2023-01-11 16:23:16 +08:00
func (s *groupServer) GetSuperGroupsInfo(ctx context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
2023-02-07 15:48:18 +08:00
resp = &pbGroup.GetSuperGroupsInfoResp{}
if len(req.GroupIDs) == 0 {
return nil, constant.ErrArgs.Wrap("groupIDs empty")
}
2023-02-07 17:16:04 +08:00
groups, err := s.GroupInterface.FindGroup(ctx, req.GroupIDs)
2023-02-07 15:48:18 +08:00
if err != nil {
return nil, err
}
2023-02-07 17:16:04 +08:00
numMap, err := s.GroupInterface.MapSuperGroupMemberNum(ctx, req.GroupIDs)
2023-02-07 15:48:18 +08:00
if err != nil {
return nil, err
}
2023-02-08 14:41:09 +08:00
owners, err := s.GroupInterface.FindGroupMember(ctx, req.GroupIDs, nil, []int32{constant.GroupOwner})
2023-02-07 15:48:18 +08:00
if err != nil {
return nil, err
2022-05-30 16:23:15 +08:00
}
2023-02-08 14:41:09 +08:00
ownerMap := utils.SliceToMap(owners, func(e *relation.GroupMemberModel) string {
return e.GroupID
})
2023-02-07 15:48:18 +08:00
resp.GroupInfos = utils.Slice(groups, func(e *relation.GroupModel) *sdk_ws.GroupInfo {
2023-02-08 14:41:09 +08:00
return DbToPbGroupInfo(e, ownerMap[e.GroupID].UserID, numMap[e.GroupID])
2023-02-07 15:48:18 +08:00
})
2022-05-30 16:23:15 +08:00
return resp, nil
}