From a285f02631feb12f430157d1b85bb908e9eb2dac Mon Sep 17 00:00:00 2001 From: chao <48119764+withchao@users.noreply.github.com> Date: Fri, 10 Nov 2023 01:44:28 -0600 Subject: [PATCH] fix: error when querying some information about disbanded group (#1376) * fix: GetUserReqApplicationList error when there is a disbanded group chat * fix: error when querying some information about disbanded group --- internal/rpc/group/group.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 6a0ce5733..2a79c5d93 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -690,7 +690,11 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbgroup. return e.GroupID }) resp.GroupRequests = utils.Slice(groupRequests, func(e *relationtb.GroupRequestModel) *sdkws.GroupRequest { - return convert.Db2PbGroupRequest(e, userMap[e.UserID], convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, groupMemberNumMap[e.GroupID])) + var ownerUserID string + if owner, ok := ownerMap[e.GroupID]; ok { + ownerUserID = owner.UserID + } + return convert.Db2PbGroupRequest(e, userMap[e.UserID], convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerUserID, groupMemberNumMap[e.GroupID])) }) return resp, nil } @@ -1056,16 +1060,20 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbgroup.GetGroupsReq) ownerMemberMap := utils.SliceToMap(ownerMembers, func(e *relationtb.GroupMemberModel) string { return e.GroupID }) - if ids := utils.Single(groupIDs, utils.Keys(ownerMemberMap)); len(ids) > 0 { - return nil, errs.ErrDatabase.Wrap("group not owner " + strings.Join(ids, ",")) - } groupMemberNumMap, err := s.GroupDatabase.MapGroupMemberNum(ctx, groupIDs) if err != nil { return nil, err } resp.Groups = utils.Slice(groups, func(group *relationtb.GroupModel) *pbgroup.CMSGroup { - member := ownerMemberMap[group.GroupID] - return convert.Db2PbCMSGroup(group, member.UserID, member.Nickname, uint32(groupMemberNumMap[group.GroupID])) + var ( + userID string + username string + ) + if member, ok := ownerMemberMap[group.GroupID]; ok { + userID = member.UserID + username = member.Nickname + } + return convert.Db2PbCMSGroup(group, userID, username, groupMemberNumMap[group.GroupID]) }) return resp, nil } @@ -1133,9 +1141,6 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbgrou ownerMap := utils.SliceToMap(owners, func(e *relationtb.GroupMemberModel) string { return e.GroupID }) - if ids := utils.Single(groupIDs, utils.Keys(ownerMap)); len(ids) > 0 { - return nil, errs.ErrData.Wrap("group no owner", strings.Join(ids, ",")) - } groupMemberNum, err := s.GroupDatabase.MapGroupMemberNum(ctx, groupIDs) if err != nil { return nil, err @@ -1564,15 +1569,16 @@ func (s *groupServer) GetGroupUsersReqApplicationList(ctx context.Context, req * ownerMap := utils.SliceToMap(owners, func(e *relationtb.GroupMemberModel) string { return e.GroupID }) - if ids := utils.Single(groupIDs, utils.Keys(ownerMap)); len(ids) > 0 { - return nil, errs.ErrData.Wrap("group no owner", strings.Join(ids, ",")) - } groupMemberNum, err := s.GroupDatabase.MapGroupMemberNum(ctx, groupIDs) if err != nil { return nil, err } resp.GroupRequests = utils.Slice(requests, func(e *relationtb.GroupRequestModel) *sdkws.GroupRequest { - return convert.Db2PbGroupRequest(e, nil, convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, uint32(groupMemberNum[e.GroupID]))) + var ownerUserID string + if owner, ok := ownerMap[e.GroupID]; ok { + ownerUserID = owner.UserID + } + return convert.Db2PbGroupRequest(e, nil, convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerUserID, groupMemberNum[e.GroupID])) }) resp.Total = total return resp, nil