From a8fa9431421e2f90537308a54b49c7046aec2eab Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 15 Jun 2023 10:52:41 +0800 Subject: [PATCH] PageGetGroupMember --- internal/rpc/group/fill.go | 32 ++++++++++++++++++++++++++++++++ internal/rpc/group/group.go | 16 ++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/internal/rpc/group/fill.go b/internal/rpc/group/fill.go index 0e3abff43..4302e3bf0 100644 --- a/internal/rpc/group/fill.go +++ b/internal/rpc/group/fill.go @@ -77,3 +77,35 @@ func (s *groupServer) TakeGroupOwner(ctx context.Context, groupID string) (*rela } return owner, nil } + +func (s *groupServer) PageGetGroupMember(ctx context.Context, groupID string, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error) { + total, members, err := s.GroupDatabase.PageGetGroupMember(ctx, groupID, pageNumber, showNumber) + if err != nil { + return 0, nil, err + } + emptyUserIDs := make(map[string]struct{}) + for _, member := range members { + if member.Nickname == "" || member.FaceURL == "" { + emptyUserIDs[member.UserID] = struct{}{} + } + } + if len(emptyUserIDs) > 0 { + users, err := s.User.GetPublicUserInfoMap(ctx, utils.Keys(emptyUserIDs), true) + if err != nil { + return 0, nil, err + } + for i, member := range members { + user, ok := users[member.UserID] + if !ok { + continue + } + if member.Nickname == "" { + members[i].Nickname = user.Nickname + } + if member.FaceURL == "" { + members[i].FaceURL = user.FaceURL + } + } + } + return total, members, nil +} diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 2fb35c0b3..d1a4dc1e4 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -410,25 +410,13 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) { resp := &pbGroup.GetGroupMemberListResp{} - total, members, err := s.GroupDatabase.PageGetGroupMember(ctx, req.GroupID, req.Pagination.PageNumber, req.Pagination.ShowNumber) + total, members, err := s.PageGetGroupMember(ctx, req.GroupID, req.Pagination.PageNumber, req.Pagination.ShowNumber) log.ZDebug(ctx, "GetGroupMemberList", "total", total, "members", members, "length", len(members)) if err != nil { return nil, err } resp.Total = total - nameMap, err := s.GetUsernameMap(ctx, utils.Filter(members, func(e *relationTb.GroupMemberModel) (string, bool) { - return e.UserID, e.Nickname == "" - }), true) - if err != nil { - return nil, err - } - log.ZDebug(ctx, "GetGroupMemberList", "nameMap", nameMap) - resp.Members = utils.Slice(members, func(e *relationTb.GroupMemberModel) *sdkws.GroupMemberFullInfo { - if e.Nickname == "" { - e.Nickname = nameMap[e.UserID] - } - return convert.Db2PbGroupMember(e) - }) + resp.Members = utils.Batch(convert.Db2PbGroupMember, members) log.ZDebug(ctx, "GetGroupMemberList", "resp", resp, "length", len(resp.Members)) return resp, nil }