diff --git a/internal/conversation_msg/conversation_msg.go b/internal/conversation_msg/conversation_msg.go index 9f6f1bca9..dc85c0a48 100644 --- a/internal/conversation_msg/conversation_msg.go +++ b/internal/conversation_msg/conversation_msg.go @@ -5,10 +5,11 @@ import ( "encoding/json" "errors" "fmt" - sdk "github.com/openimsdk/openim-sdk-core/v3/pkg/sdk_params_callback" "math" "sync" + sdk "github.com/openimsdk/openim-sdk-core/v3/pkg/sdk_params_callback" + "github.com/openimsdk/openim-sdk-core/v3/pkg/api" "github.com/openimsdk/openim-sdk-core/v3/pkg/cache" "github.com/openimsdk/tools/utils/stringutil" @@ -924,6 +925,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations if err != nil { return err } + groups := datautil.SliceToMap(groupInfoList, func(groupInfo *model_struct.LocalGroup) string { return groupInfo.GroupID }) @@ -935,8 +937,10 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations conversation.FaceURL = v.FaceURL conversation.ShowName = v.Nickname } else { - log.ZWarn(ctx, "user info not found", errors.New("user not found"), - "userID", conversation.UserID) + log.ZWarn(ctx, "user info not found", errors.New("user not found"),"userID", conversation.UserID) + + conversation.FaceURL = "" + conversation.ShowName = "UserNotFound" } } else if conversation.ConversationType == constant.ReadGroupChatType { if v, ok := groups[conversation.GroupID]; ok { @@ -949,6 +953,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations } } + return nil } @@ -979,10 +984,12 @@ func (c *Conversation) batchGetUserNameAndFaceURL(ctx context.Context, userIDs . } m[localFriend.FriendUserID] = userInfo } + usersInfo, err := c.user.GetUsersInfoWithCache(ctx, notInFriend) if err != nil { return nil, err } + for _, userInfo := range usersInfo { m[userInfo.UserID] = userInfo } diff --git a/internal/user/api.go b/internal/user/api.go index 6fef37300..77877b344 100644 --- a/internal/user/api.go +++ b/internal/user/api.go @@ -16,9 +16,9 @@ import ( "github.com/openimsdk/tools/utils/datautil" ) -// GetSingleUserFromSvr retrieves user information from the server. -func (u *User) GetSingleUserFromSvr(ctx context.Context, userID string) (*model_struct.LocalUser, error) { - users, err := u.GetUsersInfoFromSvr(ctx, []string{userID}) +// GetSingleUserFromServer retrieves user information from the server. +func (u *User) GetSingleUserFromServer(ctx context.Context, userID string) (*model_struct.LocalUser, error) { + users, err := u.GetUsersInfoFromServer(ctx, []string{userID}) if err != nil { return nil, err } @@ -125,10 +125,18 @@ func (u *User) ProcessUserCommandUpdate(ctx context.Context, userCommand *userPb // GetUserInfoFromServer retrieves user information from the server. func (u *User) GetUserInfoFromServer(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) { + var err error + serverUsersInfo, err := u.getUsersInfo(ctx, userIDs) if err != nil { return nil, err } + + if len(serverUsersInfo) == 0 { + log.ZError(ctx, "serverUsersInfo is empty", err, "userIDs", userIDs) + return nil, err + } + return datautil.Batch(ServerUserToLocalUser, serverUsersInfo), nil } @@ -171,11 +179,11 @@ func (u *User) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdk_struc return res, nil } -// GetUsersInfoFromSvr retrieves user information from the server. -func (u *User) GetUsersInfoFromSvr(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) { +// GetUsersInfoFromServer retrieves user information from the server. +func (u *User) GetUsersInfoFromServer(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) { users, err := u.getUsersInfo(ctx, userIDs) if err != nil { - return nil, sdkerrs.WrapMsg(err, "GetUsersInfoFromSvr failed") + return nil, sdkerrs.WrapMsg(err, "GetUsersInfoFromServer failed") } return datautil.Batch(ServerUserToLocalUser, users), nil } diff --git a/internal/user/full_sync.go b/internal/user/full_sync.go index a3646b9f2..e4fbe5d37 100644 --- a/internal/user/full_sync.go +++ b/internal/user/full_sync.go @@ -3,6 +3,7 @@ package user import ( "context" "errors" + "github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct" userPb "github.com/openimsdk/protocol/user" "github.com/openimsdk/tools/errs" @@ -11,7 +12,7 @@ import ( ) func (u *User) SyncLoginUserInfo(ctx context.Context) error { - remoteUser, err := u.GetSingleUserFromSvr(ctx, u.loginUserID) + remoteUser, err := u.GetSingleUserFromServer(ctx, u.loginUserID) if err != nil { return err } @@ -28,7 +29,7 @@ func (u *User) SyncLoginUserInfo(ctx context.Context) error { } func (u *User) SyncLoginUserInfoWithoutNotice(ctx context.Context) error { - remoteUser, err := u.GetSingleUserFromSvr(ctx, u.loginUserID) + remoteUser, err := u.GetSingleUserFromServer(ctx, u.loginUserID) if err != nil { return err }