fix GetUserInGroupMembers nil panic (#1324)

pull/1344/head
a3d21 1 year ago committed by GitHub
parent 3d3781f8d8
commit 1aef30dac4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -475,11 +475,13 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbgroup.GetGro
return nil, err return nil, err
} }
resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
if userInfo, ok := publicUserInfoMap[e.UserID]; ok {
if e.Nickname == "" { if e.Nickname == "" {
e.Nickname = publicUserInfoMap[e.UserID].Nickname e.Nickname = userInfo.Nickname
} }
if e.FaceURL == "" { if e.FaceURL == "" {
e.FaceURL = publicUserInfoMap[e.UserID].FaceURL e.FaceURL = userInfo.FaceURL
}
} }
return convert.Db2PbGroupMember(e) return convert.Db2PbGroupMember(e)
}) })
@ -626,11 +628,13 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbgroup.GetG
return nil, err return nil, err
} }
resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
if userInfo, ok := publicUserInfoMap[e.UserID]; ok {
if e.Nickname == "" { if e.Nickname == "" {
e.Nickname = publicUserInfoMap[e.UserID].Nickname e.Nickname = userInfo.Nickname
} }
if e.FaceURL == "" { if e.FaceURL == "" {
e.FaceURL = publicUserInfoMap[e.UserID].FaceURL e.FaceURL = userInfo.FaceURL
}
} }
return convert.Db2PbGroupMember(e) return convert.Db2PbGroupMember(e)
}) })
@ -1073,18 +1077,20 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbgroup.GetGr
return nil, err return nil, err
} }
resp.Total = total resp.Total = total
nameMap, err := s.GetPublicUserInfoMap(ctx, utils.Filter(members, func(e *relationtb.GroupMemberModel) (string, bool) { publicUserInfoMap, err := s.GetPublicUserInfoMap(ctx, utils.Filter(members, func(e *relationtb.GroupMemberModel) (string, bool) {
return e.UserID, e.Nickname == "" || e.FaceURL == "" return e.UserID, e.Nickname == "" || e.FaceURL == ""
}), true) }), true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
if userInfo, ok := publicUserInfoMap[e.UserID]; ok {
if e.Nickname == "" { if e.Nickname == "" {
e.Nickname = nameMap[e.UserID].Nickname e.Nickname = userInfo.Nickname
} }
if e.FaceURL == "" { if e.FaceURL == "" {
e.FaceURL = nameMap[e.UserID].FaceURL e.FaceURL = userInfo.FaceURL
}
} }
return convert.Db2PbGroupMember(e) return convert.Db2PbGroupMember(e)
}) })
@ -1471,17 +1477,19 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbgroup.Ge
return nil, err return nil, err
} }
publicUserInfoMap, err := s.GetPublicUserInfoMap(ctx, utils.Filter(members, func(e *relationtb.GroupMemberModel) (string, bool) { publicUserInfoMap, err := s.GetPublicUserInfoMap(ctx, utils.Filter(members, func(e *relationtb.GroupMemberModel) (string, bool) {
return e.UserID, e.Nickname == "" return e.UserID, e.Nickname == "" || e.FaceURL == ""
}), true) }), true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
if userInfo, ok := publicUserInfoMap[e.UserID]; ok {
if e.Nickname == "" { if e.Nickname == "" {
e.Nickname = publicUserInfoMap[e.UserID].Nickname e.Nickname = userInfo.Nickname
} }
if e.FaceURL == "" { if e.FaceURL == "" {
e.FaceURL = publicUserInfoMap[e.UserID].FaceURL e.FaceURL = userInfo.FaceURL
}
} }
return convert.Db2PbGroupMember(e) return convert.Db2PbGroupMember(e)
}) })
@ -1513,11 +1521,13 @@ func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbgroup.
return nil, err return nil, err
} }
resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
if userInfo, ok := publicUserInfoMap[e.UserID]; ok {
if e.Nickname == "" { if e.Nickname == "" {
e.Nickname = publicUserInfoMap[e.UserID].Nickname e.Nickname = userInfo.Nickname
} }
if e.FaceURL == "" { if e.FaceURL == "" {
e.FaceURL = publicUserInfoMap[e.UserID].FaceURL e.FaceURL = userInfo.FaceURL
}
} }
return convert.Db2PbGroupMember(e) return convert.Db2PbGroupMember(e)
}) })

Loading…
Cancel
Save