Skip to content

Commit 7fb0542

Browse files
committed
feat: improve batchUserFaceURLandName logic.
1 parent d04ecbc commit 7fb0542

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

internal/conversation_msg/conversation_msg.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
sdk "github.com/openimsdk/openim-sdk-core/v3/pkg/sdk_params_callback"
98
"math"
109
"sync"
1110

11+
sdk "github.com/openimsdk/openim-sdk-core/v3/pkg/sdk_params_callback"
12+
1213
"github.com/openimsdk/openim-sdk-core/v3/pkg/api"
1314
"github.com/openimsdk/openim-sdk-core/v3/pkg/cache"
1415
"github.com/openimsdk/tools/utils/stringutil"
@@ -920,10 +921,26 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
920921
return err
921922
}
922923

924+
var handleUserIDs []string
925+
926+
for userID := range users {
927+
handleUserIDs = append(handleUserIDs, userID)
928+
}
929+
930+
loseUserIDs := datautil.Single(userIDs, handleUserIDs)
931+
932+
if len(loseUserIDs) != 0 {
933+
for _, userID := range loseUserIDs {
934+
users[userID] = &model_struct.LocalUser{UserID: userID, Nickname: "UserNotFound", FaceURL: ""}
935+
}
936+
log.ZError(ctx, "lose usersInfo", errs.New("userInfo not found"), "loseUserIDs", loseUserIDs)
937+
}
938+
923939
groupInfoList, err := c.group.GetSpecifiedGroupsInfo(ctx, groupIDs)
924940
if err != nil {
925941
return err
926942
}
943+
927944
groups := datautil.SliceToMap(groupInfoList, func(groupInfo *model_struct.LocalGroup) string {
928945
return groupInfo.GroupID
929946
})
@@ -949,6 +966,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
949966

950967
}
951968
}
969+
952970
return nil
953971
}
954972

@@ -984,7 +1002,7 @@ func (c *Conversation) batchGetUserNameAndFaceURL(ctx context.Context, userIDs .
9841002
if err != nil {
9851003
return nil, err
9861004
}
987-
1005+
9881006
for _, userInfo := range usersInfo {
9891007
m[userInfo.UserID] = userInfo
9901008
}

internal/user/api.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,18 @@ func (u *User) ProcessUserCommandUpdate(ctx context.Context, userCommand *userPb
125125

126126
// GetUserInfoFromServer retrieves user information from the server.
127127
func (u *User) GetUserInfoFromServer(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) {
128+
var err error
129+
128130
serverUsersInfo, err := u.getUsersInfo(ctx, userIDs)
129131
if err != nil {
130132
return nil, err
131133
}
134+
135+
if len(serverUsersInfo) == 0 {
136+
log.ZError(ctx, "serverUsersInfo is empty", err, "userIDs", userIDs)
137+
return nil, err
138+
}
139+
132140
return datautil.Batch(ServerUserToLocalUser, serverUsersInfo), nil
133141
}
134142

0 commit comments

Comments
 (0)