From 1aef30dac4c9d870896610c84cc79d0f814d860b Mon Sep 17 00:00:00 2001 From: a3d21 <93191329+a3d21@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:21:31 +0800 Subject: [PATCH] fix GetUserInGroupMembers nil panic (#1324) --- internal/rpc/group/group.go | 64 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 38dd0c32c..17d748920 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -475,11 +475,13 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbgroup.GetGro return nil, err } resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { - if e.Nickname == "" { - e.Nickname = publicUserInfoMap[e.UserID].Nickname - } - if e.FaceURL == "" { - e.FaceURL = publicUserInfoMap[e.UserID].FaceURL + if userInfo, ok := publicUserInfoMap[e.UserID]; ok { + if e.Nickname == "" { + e.Nickname = userInfo.Nickname + } + if e.FaceURL == "" { + e.FaceURL = userInfo.FaceURL + } } return convert.Db2PbGroupMember(e) }) @@ -626,11 +628,13 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbgroup.GetG return nil, err } resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { - if e.Nickname == "" { - e.Nickname = publicUserInfoMap[e.UserID].Nickname - } - if e.FaceURL == "" { - e.FaceURL = publicUserInfoMap[e.UserID].FaceURL + if userInfo, ok := publicUserInfoMap[e.UserID]; ok { + if e.Nickname == "" { + e.Nickname = userInfo.Nickname + } + if e.FaceURL == "" { + e.FaceURL = userInfo.FaceURL + } } return convert.Db2PbGroupMember(e) }) @@ -1073,18 +1077,20 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbgroup.GetGr return nil, err } 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 == "" }), true) if err != nil { return nil, err } resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { - if e.Nickname == "" { - e.Nickname = nameMap[e.UserID].Nickname - } - if e.FaceURL == "" { - e.FaceURL = nameMap[e.UserID].FaceURL + if userInfo, ok := publicUserInfoMap[e.UserID]; ok { + if e.Nickname == "" { + e.Nickname = userInfo.Nickname + } + if e.FaceURL == "" { + e.FaceURL = userInfo.FaceURL + } } return convert.Db2PbGroupMember(e) }) @@ -1471,17 +1477,19 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbgroup.Ge return nil, err } 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) if err != nil { return nil, err } resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { - if e.Nickname == "" { - e.Nickname = publicUserInfoMap[e.UserID].Nickname - } - if e.FaceURL == "" { - e.FaceURL = publicUserInfoMap[e.UserID].FaceURL + if userInfo, ok := publicUserInfoMap[e.UserID]; ok { + if e.Nickname == "" { + e.Nickname = userInfo.Nickname + } + if e.FaceURL == "" { + e.FaceURL = userInfo.FaceURL + } } return convert.Db2PbGroupMember(e) }) @@ -1513,11 +1521,13 @@ func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbgroup. return nil, err } resp.Members = utils.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo { - if e.Nickname == "" { - e.Nickname = publicUserInfoMap[e.UserID].Nickname - } - if e.FaceURL == "" { - e.FaceURL = publicUserInfoMap[e.UserID].FaceURL + if userInfo, ok := publicUserInfoMap[e.UserID]; ok { + if e.Nickname == "" { + e.Nickname = userInfo.Nickname + } + if e.FaceURL == "" { + e.FaceURL = userInfo.FaceURL + } } return convert.Db2PbGroupMember(e) })