Skip to content

Commit e2389f1

Browse files
authored
fix: improve batchUserFaceURLandName logic. (#756)
* refactor: update ServerAPI method name. * feat: improve batchUserFaceURLandName logic. * update logic.
1 parent 476b148 commit e2389f1

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

internal/conversation_msg/conversation_msg.go

+10-3
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"
@@ -924,6 +925,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
924925
if err != nil {
925926
return err
926927
}
928+
927929
groups := datautil.SliceToMap(groupInfoList, func(groupInfo *model_struct.LocalGroup) string {
928930
return groupInfo.GroupID
929931
})
@@ -935,8 +937,10 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
935937
conversation.FaceURL = v.FaceURL
936938
conversation.ShowName = v.Nickname
937939
} else {
938-
log.ZWarn(ctx, "user info not found", errors.New("user not found"),
939-
"userID", conversation.UserID)
940+
log.ZWarn(ctx, "user info not found", errors.New("user not found"),"userID", conversation.UserID)
941+
942+
conversation.FaceURL = ""
943+
conversation.ShowName = "UserNotFound"
940944
}
941945
} else if conversation.ConversationType == constant.ReadGroupChatType {
942946
if v, ok := groups[conversation.GroupID]; ok {
@@ -949,6 +953,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
949953

950954
}
951955
}
956+
952957
return nil
953958
}
954959

@@ -979,10 +984,12 @@ func (c *Conversation) batchGetUserNameAndFaceURL(ctx context.Context, userIDs .
979984
}
980985
m[localFriend.FriendUserID] = userInfo
981986
}
987+
982988
usersInfo, err := c.user.GetUsersInfoWithCache(ctx, notInFriend)
983989
if err != nil {
984990
return nil, err
985991
}
992+
986993
for _, userInfo := range usersInfo {
987994
m[userInfo.UserID] = userInfo
988995
}

internal/user/api.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
"github.com/openimsdk/tools/utils/datautil"
1717
)
1818

19-
// GetSingleUserFromSvr retrieves user information from the server.
20-
func (u *User) GetSingleUserFromSvr(ctx context.Context, userID string) (*model_struct.LocalUser, error) {
21-
users, err := u.GetUsersInfoFromSvr(ctx, []string{userID})
19+
// GetSingleUserFromServer retrieves user information from the server.
20+
func (u *User) GetSingleUserFromServer(ctx context.Context, userID string) (*model_struct.LocalUser, error) {
21+
users, err := u.GetUsersInfoFromServer(ctx, []string{userID})
2222
if err != nil {
2323
return nil, err
2424
}
@@ -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

@@ -171,11 +179,11 @@ func (u *User) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdk_struc
171179
return res, nil
172180
}
173181

174-
// GetUsersInfoFromSvr retrieves user information from the server.
175-
func (u *User) GetUsersInfoFromSvr(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) {
182+
// GetUsersInfoFromServer retrieves user information from the server.
183+
func (u *User) GetUsersInfoFromServer(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) {
176184
users, err := u.getUsersInfo(ctx, userIDs)
177185
if err != nil {
178-
return nil, sdkerrs.WrapMsg(err, "GetUsersInfoFromSvr failed")
186+
return nil, sdkerrs.WrapMsg(err, "GetUsersInfoFromServer failed")
179187
}
180188
return datautil.Batch(ServerUserToLocalUser, users), nil
181189
}

internal/user/full_sync.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package user
33
import (
44
"context"
55
"errors"
6+
67
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
78
userPb "github.com/openimsdk/protocol/user"
89
"github.com/openimsdk/tools/errs"
@@ -11,7 +12,7 @@ import (
1112
)
1213

1314
func (u *User) SyncLoginUserInfo(ctx context.Context) error {
14-
remoteUser, err := u.GetSingleUserFromSvr(ctx, u.loginUserID)
15+
remoteUser, err := u.GetSingleUserFromServer(ctx, u.loginUserID)
1516
if err != nil {
1617
return err
1718
}
@@ -28,7 +29,7 @@ func (u *User) SyncLoginUserInfo(ctx context.Context) error {
2829
}
2930

3031
func (u *User) SyncLoginUserInfoWithoutNotice(ctx context.Context) error {
31-
remoteUser, err := u.GetSingleUserFromSvr(ctx, u.loginUserID)
32+
remoteUser, err := u.GetSingleUserFromServer(ctx, u.loginUserID)
3233
if err != nil {
3334
return err
3435
}

0 commit comments

Comments
 (0)