Skip to content

Commit

Permalink
feat: improve batchUserFaceURLandName logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et committed Oct 25, 2024
1 parent d04ecbc commit 7fb0542
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 20 additions & 2 deletions internal/conversation_msg/conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -920,10 +921,26 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
return err
}

var handleUserIDs []string

for userID := range users {
handleUserIDs = append(handleUserIDs, userID)
}

loseUserIDs := datautil.Single(userIDs, handleUserIDs)

if len(loseUserIDs) != 0 {
for _, userID := range loseUserIDs {
users[userID] = &model_struct.LocalUser{UserID: userID, Nickname: "UserNotFound", FaceURL: ""}
}
log.ZError(ctx, "lose usersInfo", errs.New("userInfo not found"), "loseUserIDs", loseUserIDs)
}

groupInfoList, err := c.group.GetSpecifiedGroupsInfo(ctx, groupIDs)
if err != nil {
return err
}

groups := datautil.SliceToMap(groupInfoList, func(groupInfo *model_struct.LocalGroup) string {
return groupInfo.GroupID
})
Expand All @@ -949,6 +966,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations

}
}

return nil
}

Expand Down Expand Up @@ -984,7 +1002,7 @@ func (c *Conversation) batchGetUserNameAndFaceURL(ctx context.Context, userIDs .
if err != nil {
return nil, err
}

for _, userInfo := range usersInfo {
m[userInfo.UserID] = userInfo
}
Expand Down
8 changes: 8 additions & 0 deletions internal/user/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7fb0542

Please sign in to comment.